已发送但未收到PHP Mailer电子邮件

时间:2020-04-08 10:25:33

标签: php phpmailer

我正在使用PHP邮件程序发送电子邮件。

PHP邮件调试器告诉我这一点:

2020-04-08 10:16:59 Connection: opening to 192.***.**.**:25, timeout=300, options=array()
2020-04-08 10:16:59 Connection: opened
2020-04-08 10:16:59 SERVER -> CLIENT: 220 SRVEX01.***.local Microsoft ESMTP MAIL Service ready at Wed, 8 Apr 2020 12:16:59 +0200
2020-04-08 10:16:59 CLIENT -> SERVER: EHLO ncrapp.***.nl
2020-04-08 10:16:59 SERVER -> CLIENT: 250-SRVEX01.***.local Hello [192.168.50.31]250-SIZE 104857600250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-X-ANONYMOUSTLS250-AUTH NTLM250-X-EXPS GSSAPI NTLM250-8BITMIME250-BINARYMIME250-CHUNKING250 XRDST
2020-04-08 10:16:59 CLIENT -> SERVER: MAIL FROM:<Flow.Info@***.nl>
2020-04-08 10:16:59 SERVER -> CLIENT: 250 2.1.0 Sender OK
2020-04-08 10:16:59 CLIENT -> SERVER: RCPT TO:<rob@***.nl>
2020-04-08 10:16:59 SERVER -> CLIENT: 250 2.1.5 Recipient OK
2020-04-08 10:16:59 CLIENT -> SERVER: RCPT TO:<ronnie@***.nl>
2020-04-08 10:16:59 SERVER -> CLIENT: 250 2.1.5 Recipient OK
2020-04-08 10:16:59 CLIENT -> SERVER: RCPT TO:<koen@***.nl>
2020-04-08 10:16:59 SERVER -> CLIENT: 250 2.1.5 Recipient OK
2020-04-08 10:16:59 CLIENT -> SERVER: DATA
2020-04-08 10:16:59 SERVER -> CLIENT: 354 Start mail input; end with <CRLF>.<CRLF>
2020-04-08 10:16:59 CLIENT -> SERVER: Date: Wed, 8 Apr 2020 12:16:59 +0200
2020-04-08 10:16:59 CLIENT -> SERVER: To: rob@***.nl, ronnie@***.nl, koen@***.nl
2020-04-08 10:16:59 CLIENT -> SERVER: From: Flow.Info@***.nl
2020-04-08 10:16:59 CLIENT -> SERVER: Subject: Test Mail
2020-04-08 10:16:59 CLIENT -> SERVER: Message-ID: <mUgoSkvhJrgVz1iGjf0wTNZ0RPaIWMxpxujmhFRzdw@ncrapp.***.nl>
2020-04-08 10:16:59 CLIENT -> SERVER: X-Mailer: PHPMailer 6.0.1 (https://github.com/PHPMailer/PHPMailer)
2020-04-08 10:16:59 CLIENT -> SERVER: MIME-Version: 1.0
2020-04-08 10:16:59 CLIENT -> SERVER: Content-Type: text/html; charset=iso-8859-1
2020-04-08 10:16:59 CLIENT -> SERVER:
2020-04-08 10:16:59 CLIENT -> SERVER: Test Mail
2020-04-08 10:16:59 CLIENT -> SERVER:
2020-04-08 10:16:59 CLIENT -> SERVER: .
2020-04-08 10:16:59 SERVER -> CLIENT: 250 2.6.0 <mUgoSkvhJrgVz1iGjf0wTNZ0RPaIWMxpxujmhFRzdw@ncrapp.***.nl> [InternalId=108795816574987, Hostname=SRVEX01.***.local] 1719 bytes in 0.096, 17,471 KB/sec Queued mail for delivery
2020-04-08 10:16:59 CLIENT -> SERVER: QUIT
2020-04-08 10:16:59 SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel
2020-04-08 10:16:59 Connection: closed

我有多个电子邮件发送地址。 一切似乎都还可以,但是有些邮件地址从未收到过电子邮件。

我(Rob)收到了电子邮件,但其他2名员工未收到电子邮件。 我接受培训的公司大约有100名员工,其中10名员工无法从我的申请中收到电子邮件。

这是编程问题吗?还是邮件服务器有问题?

我的代码:

use PHPMailer\PHPMailer\PHPMailer;
include_once "PHPMailer/PHPMailer.php";
include_once "PHPMailer/Exception.php";
include_once "PHPMailer/SMTP.php";

$mail = new PHPMailer();

$mail->SMTPDebug = 3;

$mail->Host = "192.***.**.**";
$mail->isSMTP();
$mail->SMTPAuth = false;
$mail->Username = "***";
$mail->Password = "***";
$mail->Port = 25;

$mail->addAddress("rob@***.nl");
$mail->addAddress("ronnie@***.nl");
$mail->addAddress("koen@***.nl");

$mail->setFrom('Flow.Info@***.nl');

$mail->Subject = "Test Mail";
$mail->isHTML(true);

$mail->Body = "Test Mail";

$mail->send();

2 个答案:

答案 0 :(得分:0)

您已成功将邮件传递到本地邮件服务器,此后您的脚本不再涉及-邮件服务器将负责之后的所有工作,因此您需要查看邮件服务器的日志以查看发生的情况到此之后的邮件,或者将邮件服务器中的反弹传回脚本环境。

您还运行了相当旧的PHPMailer版本,因此请升级。

答案 1 :(得分:0)

调试

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

打开您的Google管理控制台(admin.google.com)。

点击安全>基本设置。

在“安全性较低的应用程序”下,选择“转到安全性较弱的应用程序的设置”。

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

点击“保存”按钮。

使用最新的PHPMAILER代码

// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

// Load Composer's autoloader
require 'vendor/autoload.php';

// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);

try {
    //Server settings
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      // Enable verbose debug output
    $mail->isSMTP();                                            // Send using SMTP
    $mail->Host       = 'smtp1.example.com';                    // Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
    $mail->Username   = 'user@example.com';                     // SMTP username
    $mail->Password   = 'secret';                               // SMTP password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
    $mail->Port       = 587;                                    // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above

    //Recipients
    $mail->setFrom('from@example.com', 'Mailer');
    $mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
    $mail->addAddress('ellen@example.com');               // Name is optional
    $mail->addReplyTo('info@example.com', 'Information');
    $mail->addCC('cc@example.com');
    $mail->addBCC('bcc@example.com');

    // Attachments
    $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    // Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}```