If you have setup a new server and your PHP mail() function is failing, it’s just because Sendmail isn’t installed on your server. So, Here we’ll let you know some simple setps to fix this problem.
To Configuring Sendmail on Ubuntu, you need to run following commands on your server.
Install Sendmail on Ubuntu
sudo apt-get install sendmail
Update your hosts file
sudo nano /etc/hosts
Make sure the line something like below at the top:
127.0.1.1 yourhost yourhost 127.0.0.1 localhost
Change the second line to look like this, where yourhost is the same as whatever is in the line above it.
127.0.0.1 localhost localhost.localdomain yourhost
Save the file and then Run Sendmail’s config command and answer ‘Y’ to everything:
Sendmail Installation and Configuration is done. Now Finally you need to Restart Apache. Run the following command to restart Apache services:
sudo service apache2 restart
Bingo! Sendmail is now installed and configured, and your PHP mail() function is working and it will send mail quickly now.