如何解决PHPMailer效果不佳
我知道Google上有很多类似的问题,但是我找不到适合我的情况的其他论坛。当我删除$ mail-> isSMTP(); PHPMailer返回此错误: 无法实例化邮件功能。 无法发送消息。Mailer错误:无法实例化邮件功能。 但是当我离开它时,页面不会加载并返回错误503。这是我的代码:
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();
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "**************"; // gmail acccounts
$mail->Password = "****************"; // the passwords
$mail->setFrom('*******************','No Reply'); // de qui le mail doit être envoyé.
$mail->addAddress('****************'); // à qui le message doit être envoyé.
$mail->Subject = 'Test Email via PHPMailer';
//$mail->msgHTML(file_get_contents('contents.html'),__DIR__); external html file.
$mail->isHTML(true);
$mail->Body = "<h1>Send HTML Email using SMTP in PHP</h1><p>This is a test email I’m sending using SMTP mail server with PHPMailer.</p>";
if($mail->send()) {
echo 'Message has been sent';
} else {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。