【发布时间】:2020-06-25 05:21:47
【问题描述】:
我已经使用 composer composer require phpmailer/phpmailer 安装了 php mailer。我按照本网站https://www.geeksforgeeks.org/how-to-send-an-email-using-phpmailer 的说明进行操作。
以下是我发送电子邮件的代码。
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try
{
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'mail.example.in';
$mail->SMTPAuth = true;
$mail->Username = 'username';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('owner@gmail.com', 'Owner');
$mail->addAddress('receipent@gmail.com');
$mail->isHTML(true);
$mail->Subject = "Hello this is subject";
$mail->Body = "Hello this is message;
$mail->send();
echo "Mail has been sent successfully!";
}
catch (Exception $e)
{
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
当我评论 $mail->isSMTP(); 并发送邮件时,我得到的结果是消息已发送,但我的 Gmail 收件箱中没有。
当我取消注释 $mail->isSMTP(); 时,我收到如下图所示的错误消息。
我的项目托管在 godaddy 服务器上。 即使我使用 php mail() 函数发送邮件,响应是邮件发送成功,但它没有传递到我的 Gmail 收件箱中
【问题讨论】:
-
看来您的问题与This 有关。报错信息肯定是一样的,原因大概也是一样的。
-
这能回答你的问题吗? Could not connect to SMTP host
标签: php smtp phpmailer starttls