When I develop the email function on my localhost, I like to set the Gmail for sending an email from my localhost. It is convenient and easy to set up. Today, I will share how to set up the Gmail account to send an email in your WAMP from your computer. Note, this method works for Windows only. Okay, let’s do it…
Download sendmail.zip
Sendemail.exe is a simple windows console application that emulates sendmail’s “-t” option to deliver emails piped via stdin. It is intended to ease running Unix code that has <code>/usr/lib/sendmail</code> hardcode as an email delivery means. It doesn’t support deferred delivery and requires an SMTP server to perform the actual delivery of the messages.
download sendmail.zip
Install Sendmail
- Extract and paste the Sendmail folder at “C:\wamp64\” location.
- Inside the Sendmail folder, find the sendmail.ini and edit with the following setting.
smtp_server=smtp.gmail.com smtp_port=587 auth_username=your_username auth_password=your_password<span id="mce_marker" data-mce-type="bookmark" data-mce-fragment="1"></span>
- Save and close the file
Configure php.ini
- At the wamp icon on the right bottom corner, click on that wamp icon then go to PHP and php.ini. Then follows this setting.
[mail function] SMTP=smtp.gmail.com smtp_port=587 sendmail_path = "C:\wamp64\sendmail\sendmail.exe" sendmail_from ="yourmail@gmail.com”<span id="mce_marker" data-mce-type="bookmark" data-mce-fragment="1"></span>
- Save and restart the wamp server
Test sending an email via your wamp
- You can use this snippet to test the sending of an email. Simply creates the send_email_testing.php at your web root. For Wamp, the web root will be “C:\wamp64\www”. Then add the snippet below into the file.
Snippet:
/** * Sending an email test */ $to = 'nobody@example.com'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $result = mail($to, $subject, $message, $headers); if( $result ) { echo 'Success'; }else{ echo 'Fail'; }
Make sure, your wamp is running (green icon). Then opens the browser and type http://localhost/send_email_testing.php URL. If you see “Success” message on the screen that means your email is sent. Just go to check your email.