504 Gateway Time-out when sending smtp mail via PHP even though mail arrives at destination

  • Posted November 16, 2014

I have a weird problem on one of my LEMP droplets, while the same thing whith the same E-mail account and settings works fine on other droplets: when sending an E-mail via SMTP using PHP I get a “504 Gateway Time-out”. But the E-mail is actually sent, and I tried completely different E-mail accounts which all had the same problem.

The error.log says this (for security reasons I changed the urls and IP here obviously):

2014/11/16 09:51:12 [error] 5666#0: *13 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 777.777.777.777, server:, request: “POST /ajax/shop/resend_order HTTP/1.1”, upstream: “fastcgi://unix:/var/run/php5-fpm.sock”, host: “”, referrer: “

The strange thing: because I could not remedy this, I started a new LEMP droplet and manually copied database and web space over there (I did not want to use an image to be sure I have a fresh installation and don’t copy whatever I did wrong on the old one over to the new one). And everything worked fine again!

Still I’d like to know what caused this problem since I don’t want to run into it again. I have the old droplet running, so I can throw any solution at it suggested here ;-) I’m not a Linux expert, but I’m willing to learn!

Thanks in advance, Sebastian


I also have same issue…

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I have the same problem. Did you managed to solve it? Thanks in advance!

I know this is an old thread, but have been struggling with this for the last couple of days, migrating from apache to nginx, the submitted form would be saved and the mail would be sent, but nginx would report a timeout error.

The answer lies in the mail.log file.

Jul 20 08:40:01 ubuntu18 sm-msp-queue[19799]: My unqualified host name (ubuntu18) unknown; sleeping for retry

All you have to do change the hostname to {yourhostname}.local an the gateway timeout will disappear