Laravel邮件已发送,但仍会引发异常 [英] Laravel mail sent but still throws exception
问题描述
我正在laravel中发送电子邮件,如下所示:
I am sending an email in laravel like this:
Mail::send('email.email_view', [] , function($message) {
$message->to('email@gmail.com', 'Receiver Name')
->subject('TTTTTT');
});
视图"email.email_view"仅包含以下内容:
The view "email.email_view" only contains this:
test this
发生的事情是,电子邮件已发送,我在收件箱中收到了它,但仍然抛出此异常:
What happens is that the email gets sent and I receive it in the inbox, but still it throws this exception:
local.ERROR:连接到tcp://mail.myserver.net:2525超时 {"exception":"[object](Swift_TransportException(code:0):连接 到tcp://mail.myserver.net:2525超时于 /home/public_html/test/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:473, Swift_IoException(code:0):连接到tcp://mail.myserver.net:2525 超时于 /home/public_html/test/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:166) [stacktrace]
local.ERROR: Connection to tcp://mail.myserver.net:2525 Timed Out {"exception":"[object] (Swift_TransportException(code: 0): Connection to tcp://mail.myserver.net:2525 Timed Out at /home/public_html/test/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:473, Swift_IoException(code: 0): Connection to tcp://mail.myserver.net:2525 Timed Out at /home/public_html/test/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:166) [stacktrace]
如果您需要(stacktrace)告诉我在哪里将其放置在您的网上,我知道这里有在线工具吗?.
为什么会这样?如果在整个过程中引发异常,如何防止发送电子邮件?
Why does this happen? How to prevent sending emails if an exception is thrown through the process?
推荐答案
错误回溯表明在套接字完成读取之前发生了超时.
The error traceback shows that a timeout is happening before the socket finishes being read from.
默认15 seconds
为从打开的套接字连接到电子邮件服务器读取单个数据包之间的时间间隔.
The default 15 seconds
to be enough time gap between reading of individual packets from the socket connection opened to the email server.
我建议调查您的网络连接,或者调查为什么电子邮件服务器需要很长时间才能发回数据包.
I suggest to investigate your network connection, or look into why the email server takes long to send back packets.
作为最后的手段,可以通过从服务容器解析Swift_Transport
实例并在其上调用setTimeout
方法来增加超时.在发送邮件之前执行此操作.
As a last resort, you can increase the timeout by resolving Swift_Transport
instance from the service container and calling the setTimeout
method on it. Do this before sending out mail.
https://github .com/laravel/framework/blob/v6.4.0/src/Illuminate/Mail/MailServiceProvider.php#L103
app('swift.transport')->setTimeout(60);
这篇关于Laravel邮件已发送,但仍会引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!