How to Configure PHP to Use a Local Mail Server for Sending Mail

Configure mail settings in php.ini to use a local server

Couple using laptop at table

Astronaut Images / Getty Images 

For mail functions to be available in PHP, you must have a working email system already installed. Then, you define the email configuration settings in the php.ini file.

It's easy to send mail directly from PHP scripts, but you need the right configuration in php.ini for it to work, If you run PHP on Unix or Windows with a local mail server, you might want to take advantage of that server.

The relevant setting is in the mail function section of php.ini, and it is called sendmail_path. It should be assigned the path to sendmail, typically /usr/sbin/sendmail or /usr/bin/sendmail (but check your system to get it right).

How the Configuration Should Appear

Your configuration should look like this:

[mail function]
sendmail_path = /usr/sbin/sendmail

If you use a different mail server, use its sendmail wrapper /var/qmail/bin/sendmail for qmail, for example.