How to test php mail function on localhost

On localhost if you don’t have a mail server you can’t send mails using php mail function but fortunately you can test it either mail function receiving correct parameters and its output.

Step 1
Create a logs directory somewhere you want to create, for example
I am going to create a mail/logs directory in my projects directory

$ mkdir -p /projects/logs

Step 2
Edit your php.ini file and customize sendmail_path.
Search for sendmail_path and comment out if already exists and add following line

sendmail_path = /usr/bin/tee /projects/logs/mail.out

We areĀ sending output of “mail” function to “tee” command which will write the output of mail function in mail.out file in the directory /projects/logs we created in first step.

Step 3
now call mail function

mail("", "testing php mail", "Body of test php mail() function")

Check mail function output
Now check the file in /projects/logs/mail.out it will have all the mail information right there.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s