Do I need to configure anything to use PHP mail function on fresh LAMP install?


I’m new to Digital Ocean and managing my own server.

Now that I’m comfortable with the Ubuntu 14.04 CLI, I’m going to set up a fresh LAMP installation.

Do I need to configure anything to get PHP’s mail function to work or should it work right from the new installation?

If there’s a guide that will help me, please link it for me.

Thanks for the help!



Thanks for the link, King. I appreciate the help.

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

@RoyPenrod - PHP’s mail() function requires access to the sendmail binary during compile time. If you use postfix or another alternative, you’ll need to specify this when compiling as, by default, PHP will look for sendmail and will throw an exception when compiling if it’s not available or an alternative has not been defined.

They also recommend that the path to the binary be available in your $PATH. You can run echo $PATH when logged in to the CLI to view what has been defined for the path variable. The output will look something like:


Of course, the above does not have the path to sendmail defined, though you can add an export to ~/.bashrc which will be called the next time you login, or immediately if you run source ~/.bashrc after saving the file.

You can add the path to sendmail to ~/.bashrc by running:

echo "" >> ~/.bashrc
echo "export /usr/sbin/sendmail:$PATH" >> ~/.bashrc

The first line simply adds a blank line to the end of your ~/.bashrc file (I normally do this simply to keep things neatly spaced out). The last line adds the actual export .

Wrapping it all together, you could simply do:

export SMAIL=$(which sendmail)
echo "" >> ~/.bashrc
echo "export $SMAIL:$PATH" >> ~/.bashrc
source ~/.bashrc

That’ll set SMAIL to the path where the sendmail binary is located (for the current session, which is all we need it for), add the blank line to the ~/.bashrc file, add the export to the ~/.bashrc file ($SMAIL & $PATH will expand when echo’ed in to the file) and finally call the ~/.bashrc file so that the changes take effect immediately.

@jtittle thank you so much for your detail explication, despite everything I got stuck on the same error as you @RoyPenrod

-bash: export: `/usr/sbin/sendmail:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games': not a valid identifier

could you explain me how you had solve it? You said “I didn’t include PATH= before the path list.” but I still could not understand how to go over this issue.

Is there any update for this question? It no longer works… Have tried everything here and another dozen guides. Nothing works.