If you have a WAMP server and want to send email via PHP’s mail() function, a quick way to do so is with fake sendmail for Windows.
Create a directory on your WAMP server for C:\usr\lib and put both the sendmail.exe and sendmail.ini files in there.
Edit the sendmail.ini file as below (filling in your Gmail credentials):
Click on the WAMP tray icon, select PHP and then php.ini
Make sure the [mail function] portion looks like this:
;SMTP = localhost
;smtp_port = 25
; For Win32 only.
;sendmail_from = you@yourdomain
; For Unix only. You may supply arguments as well (default: “sendmail -t -i”).
sendmail_path = “C:\usr\lib\sendmail.exe -t”
Keep in mind if you don’t use the WAMP tray icon, you want to edit the C:\wamp\bin\apache\apacheX.X.X\bin\php.ini file and not the C:\wamp\bin\php\phpX.X.X\php.ini file.
Once you’re done, you’ll need to restart the WAMP services for your php.ini edits to take effect.
You can then send a test email using this code:
// Define email parameters
$subject=’Test subject heading’;
$message=’Test body of an email’;
$headers=’From: firstname.lastname@example.org’ . “\r\n”;
$headers .= “MIME-Version: 1.0\r\n”;
$headers .= “Content-Type: text/html; charset=ISO-8859-1\r\n”;
// Send email
mail($to, $subject, $message, $headers);