How to configure sendmail as a SMART HOST

Sometimes I need to test the email functionality of a PHP website on my local machine. The best and easiest way I found so far is using sendmail as a smart host.

A smart host is a piece of software that routes email to an intermediate mail server rather than directly to the recipient’s server. The only thing you need is the SMTP address of your internet service provider. For example, my ISP is Virgin Media and their SMTP server is smtp.virgin.net.

First of all you have to install sendmail. On Ubuntu:

sudo apt-get install sendmail

Then open your configuration file:

sudo vi /etc/mail/sendmail.mc

and append or modify the following line to define your ISP SMTP server:

define(`SMART_HOST',`smtp.virgin.net')

Remove the “dnl” word at the end if there is one. Now login as root and regenerate the sendmail config file:

m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

and restart sendmail:

service sendmail restart

Now your local machine should be able to send emails. The easiest way to test is from the PHP interactive shell:

php -a
mail('myemail@domain.com','TEST','WORKING?!?');

Enjoy… :-)

One thought on “How to configure sendmail as a SMART HOST”

Leave a Reply

Your email address will not be published. Required fields are marked *