Setting up a LAMP stack server on DigitalOcean: Super Easy.
Getting a website up and running: Super Easy.
Sending an email from that website: Holy Crap.
This may be all common sense to any of those Linux gurus out there. But since I do all of my development on a Windows box and my work environment uses Cold Fusion, I am a bit of a newbie.
This is what happened.
By going to /var/log/mail.log, I noticed the error constantly:
Oct 26 21:08:57 localhost sm-msp-queue[1269]: unable to qualify my own domain name (localhost) -- using short name Oct 26 21:10:06 localhost sendmail[1398]: My unqualified host name (localhost) unknown; sleeping for retry
I also noticed on my PHP test page that it took forever to run a mail command. What the heck was going on?
After some Google troubleshooting, I found a way to test send mail by using this command
time echo test | sendmail myemail@gmail.com
This would return 3 values. One was always over a minute.
Interesting.
I then found some other snippets of help that said this error usually had to do with domain resolution. “But Internet, my hostfile looks right! Why do you say that it’s wrong?”
What was actually missing was a IPv4 entry for localhost and the name of the server. Opening up /etc/hosts and adding the following line fixes the issue.
#YOUR_HOST_NAME is actually the name of the server by using the command "hostname" 127.0.0.1 localhost.localdomain localhost YOUR_HOST_NAME
Restart sendmail by doing
sudo service sendmail restart
and you should be golden. Run the time test again, and it will be below 1 second.