Send email from PHP inside local LAMP development environment

Sendmail LAMP Very often when developing for web inside your LAMP environment you need to send emails using PHP. Configuring fully fledged email server on your Linux box is an option, although one I don't recommend. Life's too short to spend it configuring many mail transport agent of your choice configuration files just to check is your PHP application sending emails or not. In this article I'll show you how make your development environment capable of testing email sending features of your PHP applications in almost no time.

By default PHP is configured to send email using sendmail command. To make PHP and other applications work out the box most MTA agents mimic sendmail command and it's CLI interface. Why shouldn't we do the same thing using simple bash script conveniently named sendmail?

We just issue following command to create our script:

sudo nano /usr/sbin/sendmail

Then we place something like following inside:

1
2
3
4
5
6
#!/bin/bash
 
for var in "$@"
do
    logger "$var"
done

This micro BASH script just iterates trough all given parameters and send them to syslog. To make it executable we should use something like:

sudo chmod +x /usr/sbin/sendmail

Now we can just use tail to monitor syslog and read message source of any email PHP or any other application is sending using our own sendmail.

tail -f /var/log/syslog

Much easier than configuring Postfix, am I right?

DevGenii

A quality focused Magento specialized web development agency. Get in touch!

One thought on “Send email from PHP inside local LAMP development environment

Leave a Reply

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