I was recently working on a small google chrome extension and wanted to test it. The chrome extension used an iframe to open a PHP page. On submitting the form, i had the requirement to send an email. To test it i wanted to send the email using the local WAMP server as the PHP page was also hosted there. So,  How do you send emails using plain PHP mail on WAMP on Windows?

The answer is Fake SendMail.


Following to pre requisites are needed to send email via the local wamp server.

Note: We will be using Gmail as our SMTP server. You can use any other if you want.

If you have installed WampServer then unzip the Fake SendMail contents to C:\wamp\sendmail. (Only if you have installed the wamp server in the C:\wamp directory. If you have any other directory then unzip according to your directory structure)

Send Mail Configuration:

Open the sendmail.ini file located at C:\wamp\sendmail\sendmail.ini and do the following changes.


Note : The above settings are for Gmail Account.

PHP Settings:

Go to the php.ini file and set sendmail_path to the following

sendmail_path =”C:\wamp\sendmail\sendmail.exe -t”

Note: Restart your WAMP server and you are done.

Test Email:

Now, you can try to send a test email. Write a small php script to send the email.

<!--?php <br ?--> $to      = 'ToEmail@Address';
$subject = 'test email';
$message = 'testing fake send email';
$headers = 'From: FromEmail@Address' . "\r\n" .
'Reply-To: FromEmail@Address' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

if(mail($to, $subject, $message, $headers)) {
echo 'Email sent successfully!';
} else {
die('Failure: Email was not sent!');

Put the script in the www directory of the wamp server and access the directory from the browser.



Additional Notes:

1- If you are using a Gmail username/password, then make sure that your gmail account does not requires a SMS code confirmation to login. If it does then your emails will not be sent via the php code. Use some other account that does not have such settings
2- You might also have to enable the php_openssl extension in the wamp server. See the following image