Configuring Sendmail for Gmail on a WAMP server

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):

smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=auto
auth_username=yourusername@gmail.com
auth_password=yourpasswordforgmail


Click on the WAMP tray icon, select PHP and then php.ini

Make sure the [mail function] portion looks like this:

; For Win32 only.
; http://php.net/smtp
;SMTP = localhost
; http://php.net/smtp-port
;smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = you@yourdomain

; For Unix only. You may supply arguments as well (default: “sendmail -t -i”).
; http://php.net/sendmail-path
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.

wamprestartservices
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:

<?php
// Define email parameters
$to=yourtestrecipient@yourtestdomain.com;
$subject=’Test subject heading’;
$message=’Test body of an email’;
$headers=’From: yourtestsender@yourtestdomain.com’ . “\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);
?>


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *