Laravel SMTP mailtrap [Connection timed out #110]
Asked Answered
P

2

5

I'm trying to send email with Laravel using mailtrap for testing in a local homestead server.

The firewall shows no rules blocking port 2525.

Mail driver config:

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=$USERNAME
MAIL_PASSWORD=$PASSWORD
MAIL_ENCRYPTION=null

Error returned:

Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host mailtrap.io [Connection timed out #110]'
Photoreceptor answered 13/3, 2018 at 21:38 Comment(4)
If you try telnet mailtrap.io 2525 does it work?Rocky
After fighting with this for hours, I found out that if I change the host to the IPv4 address, it works.Photoreceptor
So you have a name resolution issue. Note that mailtrap.io is handled by Google for the mail and has 5 MX records.Rocky
On 8 March 2018 Mailtrap blocked the traffic from “mailtrap.io” Switching to the new host and restarting the system solved the DNS problem.Photoreceptor
S
10

Your hostname is invalid. It should be smtp.mailtrap.io. More info here: https://mailtrap.io/blog/2018-03-09-why-mailtrap-updated-its-smtp-host

P.S. Mailtrap doesn't have static IP addresses, so your way with IPv4 will work not so long amount of time.

Slumberous answered 14/3, 2018 at 10:43 Comment(2)
This appears to have solved the problem! I'm not sure why before it was returning the same error with a different host name, but I completely restarted the system and it started to function properly again. Thank you!Photoreceptor
How do you handle this error for the end-user? I mean, how do you catch this error and redirect to another page where the user can either try again or report this issue?Dorettadorette
P
1

Adding to Alexey Vasiliev answer , after you fix the hostname don't forget to clear the cache using the following commands

php artisan config:clear 
php artisan cache:clear 
Propound answered 4/11, 2018 at 16:44 Comment(1)
How do you handle this error for the end-user? I mean, how do you catch this error and redirect to another page where the user can either try again or report this issue?Dorettadorette

© 2022 - 2024 — McMap. All rights reserved.