Setting up a Ubuntu/Apache/PHP machine to send email Setting up a Ubuntu/Apache/PHP machine to send email apache apache

Setting up a Ubuntu/Apache/PHP machine to send email


sudo apt-get install sendmail will install a copy of sendmail that listens locally. If you install that, then php can use the built in mail() function. There also won't be a risk of becoming a remote relay if you install like this as well.

If you plan on sending mail out to other internet domains, you will need to make sure the IP address of the machine sending mail has a reverse DNS entry (PTR record) set up as well. Most large ISP's will reject your mail if your IP does not have a PTR record or one that points to a generic host (e.g. 1.2.3.3.domain.isp.com). It should reverse to something like mail.yourdomain.com


The native mail function is a good built-in option.

The mail function is part of the PHP core, but it does require sendmail to be installed on the server.

I believe sendmail might already be installed with the packages you have already selected, but you can check for it using the command:

dpkg --get-selections | grep sendmail

If that comes up empty, you can install sendmail with:

sudo apt-get install sendmail


sudo apt-get install sendmailsudo sendmailconfig

The second command was needed for me to run correctly. (it asks about some configuration, just type Y everytime it asks)