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.

Requirements:

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.

smtp_server=smtp.gmail.com
smtp_port=465
auth_username=user@gmail.com
auth_password=your_password

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.

References:

http://www.jacmoe.dk/how-to-send-test-emails-using-php-mail-from-your-local-wamp-installation
http://roshanbh.com.np/2007/12/sending-e-mail-from-localhost-in-php-in-windows-environment.html
http://www.dreamincode.net/forums/topic/10130-send-emails-using-php-basic/

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