首页 > 解决方案 > Swift_TransportException:预期响应代码 250,但得到代码“”,带有消息“”

问题描述

我正在从 Gmail 帐户向自己发送错误电子邮件,并且它正在工作。

突然电子邮件崩溃了,我得到了

Swift_TransportException:预期响应代码 250,但得到代码“”,消息“”。

我不确定为什么会发生这种情况,我发送了大约 80 封电子邮件。

这是我的代码:

$backup = Mail::getSwiftMailer();

// Setup your gmail mailer
$transport = \Swift_SmtpTransport::newInstance($email_config['host'], $email_config['port'], $email_config['security']);
$transport->setUsername($email_config['from_email']);
$transport->setPassword($email_config['from_email_password']);
// Any other mailer configuration stuff needed...
$gmail = new \Swift_Mailer($transport);

// Set the mailer as gmail
Mail::setSwiftMailer($gmail);


$cc = $email_config["cc"];
$to_email = $email_config["to"];

\Log::info("mail 1");
\Log::info($to_email);
// Send your message
\Mail::send('emails.error_log', ['body' => $body], function ($message) use ($from_email, $to_email, $subject, $cc) {
    $message->from($from_email);
    $message->to($to_email);
    $message->cc($cc);
    $message->subject($subject);
});
\Log::info("mail 2");

// Restore your original mailer
Mail::setSwiftMailer($backup);

标签: laravelemailgmailswiftmailer

解决方案


推荐阅读