[英]PHPMailer not working on Web Hosting
I have been able to send emails using xampp, but when I tried to use it in my online server it doesn't seem to work.我已经能够使用 xampp 发送电子邮件,但是当我尝试在我的在线服务器中使用它时,它似乎不起作用。 I tried changing the values on what was written on my email account information.
我尝试更改写在我的电子邮件帐户信息上的值。 It doesn't seem work, I was hoping for any guidance or help for anyone who has encountered this problem.
这似乎不起作用,我希望为遇到此问题的任何人提供任何指导或帮助。
This is the email account details这是电子邮件帐户的详细信息
then this is my code for my mailer.php那么这是我的mailer.php代码
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'localhost';
$mail->Username = 'email';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->Port = 465;
$mail->setFrom('email', 'Test Message');
$mail->addAddress("email");
$mail->isHTML(true);
$mail->Subject = 'This is the Subject';
$mail->Body = 'This has been sent';
$mail->AltBody = 'This has been sent';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: <br>', $mail->ErrorInfo;
}
I get the error SMTP ERROR: Failed to connect to server: Connection refused (111) SMTP connect() failed.我收到错误SMTP 错误:无法连接到服务器:连接被拒绝 (111) SMTP 连接()失败。
I am still kinda new to this, so sorry in advance for anything.我对这个还是有点陌生,所以提前抱歉。 I feel I am soo close to getting it work haha!
我觉得我离让它工作很近了哈哈!
Thanks in advance for any help!在此先感谢您的帮助! :D
:D
it's so simple... Use this code:太简单了...使用以下代码:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
$mail = new PHPMailer(true);
$name = 'Name to be displayed!';
$message = 'Never Give Up!';
$subject = 'Test mail!';
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'yourmail@gmail.com';
$mail->Password = 'youpass';
$mail->SMTPSecure = 'tls';
$mail->addReplyTo($to, $name);
$mail->setFrom($to, $name);
$mail->addAddress($to);
$mail->Subject = $subject;
$mail->msgHtml($message);
$mail->send();
?>
Hope you added PHPMailer Library in Root Directory if not then please check the path also希望您在根目录中添加了 PHPMailer 库,如果没有,请检查路径
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.