问题
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');
});
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: 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]
If you need the (stacktrace) tell me where to put it online for you guys, I understand there are online tools for it?.
Why does this happen? How to prevent sending emails if an exception is thrown through the process?
回答1:
The error traceback shows that a timeout is happening before the socket finishes being read from.
https://github.com/swiftmailer/swiftmailer/blob/v6.2.1/lib/classes/Swift/Transport/StreamBuffer.php#L159
The default 15 seconds
to be enough time gap between reading of individual packets from the socket connection opened to the email server.
https://github.com/swiftmailer/swiftmailer/blob/v6.2.1/lib/classes/Swift/Transport/StreamBuffer.php#L279
I suggest to investigate your network connection, or look into why the email server takes long to send back packets.
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);
来源:https://stackoverflow.com/questions/58228883/laravel-mail-sent-but-still-throws-exception