Laravel 邮件通过 smtp 超时错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28507664/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Mail via smtp Timeout Error
提问by Tim Lewis
I'm trying to figure out what is happening to an email sent via Laravel's Mail::...
function. The email is not being sent, and I am receiving the following error message:
我试图弄清楚通过 Laravel 的Mail::...
函数发送的电子邮件发生了什么。电子邮件未发送,我收到以下错误消息:
exception 'Swift_TransportException' with message 'Connection to mail_server:25 Timed Out' in /srv/www/application/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:405
/srv/www/application/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:405 中的异常“Swift_TransportException”和消息“Connection to mail_server:25 Timed Out”
And my app/config/mail.php
settings:
还有我的app/config/mail.php
设置:
return array(
'driver' => 'smtp',
'host' => 'mail_server',
'port' => 25,
'from' => array('address' => null, 'name' => null),
//'encryption' => 'tls',
'username' => null,
'password' => null,
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
One issue is that this usually works fine, but once in a while, I get the above error, and it seems to only happens for specific domains. For example, sending mail to [email protected]
and [email protected]
works fine, but as soon as you try sending to [email protected]
or [email protected]
the timeout message logged and the mail does not sent.
一个问题是这通常可以正常工作,但偶尔会出现上述错误,而且似乎只发生在特定域中。例如,将邮件发送到[email protected]
并且[email protected]
工作正常,但是一旦您尝试发送到[email protected]
或[email protected]
记录超时消息并且邮件没有发送。
Here's the function that sends the mail:
这是发送邮件的函数:
$message = "";
$result = Mail::send('templates.email', $form, function($mail) use (&$from_email, &$from_name, &$to_email, &$subject, &$message, &$emails){
$mail->from($from_email, $from_name);
$mail->to($to_email);
if (count($emails)>0)
$mail->cc($emails);
$mail->subject($subject);
$message = $mail->getSwiftMessage();
$message->setCharset('iso-8859-1');
$message->setMaxLineLength(1000);
$message->setContentType('multipart/mixed');
});
I figured that this was an end-user issue, as it only seems to happen to a few specific domains, but the error message indicates that the connection to my mail_server
is timing out before the mail can even be sent. If anyone else has encountered this issue, that would be great. All my attempts at finding a solution have provided answers that do not apply to Laravel or this specific problem.
我认为这是一个最终用户问题,因为它似乎只发生在少数特定域中,但错误消息表明与我的连接mail_server
在邮件发送之前就超时了。如果其他人遇到过这个问题,那就太好了。我寻找解决方案的所有尝试都提供了不适用于 Laravel 或这个特定问题的答案。
Edit
编辑
Note, all mail sent from this Laravel Application is handled in a Queue, so overworking/concurrency shouldn't be the issue here.
请注意,从此 Laravel 应用程序发送的所有邮件都在队列中处理,因此过度工作/并发不应该是这里的问题。
回答by Eric Kaburu
For Gmail,change the driver from smtp to sendmail. I have been scratching my head over this for almost an hour until I stumbled on that.
对于 Gmail,请将驱动程序从 smtp 更改为 sendmail。我一直在为此挠头将近一个小时,直到我偶然发现了它。