【问题标题】:PHPMailer GMail Email sent but ..not receivedPHPMailer GMail 电子邮件已发送但..未收到
【发布时间】:2020-04-08 17:33:29
【问题描述】:


我已安装 PHPMailer 6 并在 MVC 应用程序中使用它,如下所示,我的电子邮件显然已发送,但从未收到:

// Controller:

$this->sendmailer = new PHPMailer(true);
        //$this->sendmailer->isSMTP();
        $this->sendmailer->SMTPDebug = 2;
        $this->sendmailer->SMTPAuth = true;
        $this->sendmailer->SMTPSecure = 'tls';
        $this->sendmailer->Host = 'smtp.gmail.com';
        $this->sendmailer->Port = 587;
        $this->sendmailer->Username = 'xxxxxx@gmail.com';
        $this->sendmailer->Password = 'xxxxxxx';
        $this->sendmailer->setFrom('xxxxxxx@gmail.com', 'Test PHPMailer / GMail');

// In the inherited Controller...:


$mail=$this->sendmailer;

$subject="Mail Subject....";
$content="HTML content";

    $mail->addAddress('jmbrosselin@jmbdev.com', 'JM Brosselin');
    $mail->Subject = $subject;
    $mail->isHTML();
    $mail->msgHTML($content);

    echo '<pre>';
        echo $message;
        echo '<br/><hr><br/>';
        print_r($mail);
echo '</pre>';
    die();

注意 1:无论我使用什么 SMTP 配置(tls/587 或 ssl /465...),我已经注释掉了导致发送失败的 isSMTP() 方法;除此之外,电子邮件输出似乎是正确的;
注意 2:我已经以更简单的非 MVC 风格测试了这个配置,它完美地工作,例如,它被发送..并接收!

Oups..忘记在代码脚本中添加发送方法..显然我在原始脚本中有它:

if (!$mail->send()) {
            $message='<br/>Mailer Error: '. $mail->ErrorInfo;
        } else {
            $message='<br/>Message sent!';
        }

嗨!
感谢@Dhruvadeep。
我使用的是法语谷歌/管理控制台,所以菜单有些不同,但我确实执行了“不太安全的应用程序控制”;我没有做的是使用
require 'PHPMailerAutoload.php';”指令;相反,我使用 Composer 和以下内容:

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;


在我的“控制器”中...
我似乎读到“require 'PHPMailerAutoload.php';”已经过时了,我正在使用 PHPMailer v6.1.4…
这是正确的吗?

事实上,按照配置,Gmail 请求是“随机”工作的(……!)并且需要很长时间才能将邮件发送到收件人邮箱,或者……不是!我已经读到这可能是由于 GMail 考虑到我正在发送垃圾邮件..但这不会被过滤/从收件人邮箱,而不是从发件方(例如 GMAIL ......)?
在我当前的设置下方:

$this->sendmailer = new PHPMailer(true);
//$this->sendmailer->isSMTP();
$this->sendmailer->SMTPDebug = 2;

$this->sendmailer->Host = 'smtp.gmail.com';
//$this->sendmailer->Host =gethostbyname("smtp.gmail.com");
$this->sendmailer->Port = 587;
$this->sendmailer->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$this->sendmailer->SMTPAuth = true;
$this->sendmailer->Username = 'my_gmail_email_email@gmail.com';
$this->sendmailer->Password = 'my_gmail_email_pwd';
$this->sendmailer->setFrom('my_gmail_email_email', 'Test');

【问题讨论】:

  • 呃,这段代码没有调用send(),所以什么都不会发生。
  • 在代码转录中添加了发送指令!!
  • 启用 SMTP 并显示 SMTP 脚本
  • 这是我在启用 SMTP 和调试 = 2 时得到的结果:
    使用 587/tls 配置:2020-04-08 21:01:01 SMTP 错误:无法连接到服务器:连接被拒绝 (111)
    SMTP 连接 () 失败。 github.com/PHPMailer/PHPMailer/wiki/Troubleshooting<br>
  • 使用 ssl/465 配置:
    ... 2020-04-08 21:04:33 CLIENT ->服务器:EHLO test.soulabail.fr
    ... 2020-04-08 21:04:33 CLIENT ->服务器:[隐藏凭据]
    <accounts.google.com/signin/… 通过 Web 浏览器登录,然后重试。534-5.7.14 了解更多信息 at534 5.7.14 support.google.com/mail/answer/78754 f187sm964588wme.9 - gsmtp
    2020-04 -08 21:04:34 SMTP 错误:密码命令失败:534-5.7.14 SMTP 错误:无法验证。
    2020-04-08 21:04:34 CLIENT ->服务器:退出

标签: gmail phpmailer


【解决方案1】:

实际使用 th3 最新的 PhPMailer 指南,如下所述。 也可以通过以下方式激活 Google Less Secure App

**允许安全性较低的应用访问 Gmail

打开您的 Google 管理控制台 (admin.google.com)。 点击安全 > 基本设置。

在安全性较低的应用下,选择转到安全性较低的应用的设置。

在子窗口中,选择强制所有用户访问不太安全的应用程序单选按钮。 ...

点击保存按钮。**

require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->setFrom('from@example.com', 'Your Name');
$mail->addAddress('myfriend@example.net', 'My Friend');
$mail->Subject  = 'First PHPMailer Message';
$mail->Body     = 'Hi! This is my first e-mail sent through PHPMailer.';
if(!$mail->send()) {
  echo 'Message was not sent.';
  echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
  echo 'Message has been sent.';
}```

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-25
    • 2015-06-13
    • 2014-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多