Recently I upgraded my server and found that I was having trouble in sending mails from the linuxhomeserver.com website, as in they wouldn’t send. I spent a bit of time looking into it, and these are the steps I went through to get it working again.
1. Install sendmail: sudo apt install sendmail
2. Edit the /etc/php/7.2/apache2/php.ini file. There is a line in this in which you must specify the path to sendmail.
3. Restart the apache web server: sudo service apache2 restart
You can confirm the path by running ‘which sendmail‘. Search the php.ini file for ‘sendmail‘ and enter the correct path
While this worked, and I was able to send emails, I found that, when sending a mail from the Contact page, it took a very long time between clicking Send and for the message to appear saying the mail had been sent. I took a look at the mail log file (tail /var/log/mail.log) and found a lot of entries saying, ‘unable to qualify my own domain name‘, and ‘unknown host name; sleeping for retry‘. This means the server is not able to resolve its own hostname.
The hostname is the name you gave the server when setting it up. You can see this at your command prompt, or by running the command, ‘hostname‘. The way to tell it what IP resolves to the hostname is by editing the /etc/hosts file.
Open the hosts file (nano /etc/hosts), and at the end of the line which starts with 127.0.0.1, enter the hostname of your server.
When I tried sending a mail again, it worked straight away and the mail was sent.