Home » Php » linux – Setting up a Ubuntu/Apache/PHP machine to send email

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

Posted by: admin April 23, 2020 Leave a comment


I am working for a small Ho Chi Minh City company whose only server was just one old small computer. Now just a few months later, we are expanding rapidly and one of the requirements for new users is to require them to verify their email addresses.

There are no special programs on the Ubuntu box, instead the only thing I did on the actual server was re-format the entire hard drive from windows XP and installed Natty Narwhal on it, then install Apache and PHPMYADMIN.

I would like to have PHP to send out an email to both the user and the administrators as soon as somebody applies for membership. But I have no idea what I need to do to start.

Any ideas on what I need to set up first would be humbly appreciated; I am not looking for a step by step, just some tips to point me in the right direction.

-Duong Van

How to&Answers:

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. 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 sendmail
sudo sendmailconfig

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


I recommend installing Postfix MTA to send e-mails out the Ubuntu server:

aptitude install postfix

And using the PHP Mailer class to send e-mails from PHP: http://phpmailer.worxware.com/

For “fully featured” e-mail services my recipe is:

Postfix + DKIM-proxy + Dovecot + Roundcube + PHP Mailer + SpamAssassin + proper DNS settings + SSL certificate to enable encrypted connections

(And I prefer NginX as HTTP server…)


sendmail does the trick. You can configure sendmail to use your regular email smtp account, details are here:
and specifically for gmail here:
There is a bug in the sendmail configuration files which you can read about here: