如何使用 swiftmailer 将失败的邮件记录到数据库中

How can I log failed mails into database using swiftmailer

如何查看失败的邮件。即使我提供了无效的电子邮件地址,Swiftmailer 也会返回 true。我需要将发送和失败的邮件记录到数据库中

$message = Yii::$app->mailer->compose();
$message->attach($protocal.$_SERVER['SERVER_NAME'].$payslip);
$message->setTo("tft@sjkdsjk.dfdh");
$message->setFrom("hr@gmail.com");
$message->setSubject($vStaffName." ".$vPeriodName. " Payslip");
$message->setTextBody("Find attached copy of your payslip. To open this document use your ID number as password");

$send = $message->send();

var_dump($发送);死亡(); //returns 总是如此

我希望是对还是错

你应该检查 SMTP。

这意味着您必须连接到该电子邮件的 SMTP 服务器。

连接到 SMTP 服务器后,您应该发送这些命令:

HELO somehostname.com
MAIL FROM: <no-reply@gmail.com>
RCPT TO: <emailtovalidate@domain.com>

如果您收到“中继访问被拒绝”,则表示此电子邮件无效。

有一个简单的PHPclass。你可以使用它:

http://www.phpclasses.org/package/6650-PHP-Check-if-an-e-mail-is-valid-using-SMTP.html