Using Gmail in php mail() function


first of all thanks for your great tutorials!

However, with this one ( I encounter an issue I could not solve so far.

If I do: cat sample_email.txt | msmtp --debug -a gmail

There is a lot of console output, ending with: reading recipients from the command line

If I wait long enough (approx. 2 minutes) I receive the mail. However, the problem propagates to phps mail function. This means, if a user fills out a contact form he has to wait for approx. 2 minutes until he receives feedback.

(When googling, I usually find that the /etc/hosts file needs to be properly set, however, this is not the issue here).

Any ideas?


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.


Probably your SMTP port is closed, you need to make sure that port 587 is open for outgoing TCP connections via your firewall. You also might have to get in touch with DigitalOcean Support and ask them to open the port for you as well.