Have you installed WAMP into your PC for developing a website and looking for how to send email with it for testing your email feature is working or not? Continue reading this blog.
Unlike XAMP, WAMP does not come integrated with sendmail feature and thus you need to do something extra when you want to test your development waork in your local machiine. To configure WAMP for sending email you need to follow the below steps (assuming WAMP is already installed and working okay):
- Download the Fake Sendmail for Windows.
- Use Gmail or any other email account to configure the sendmail.
- Change te Gmail setting to allow third party email sending feature.
- Update the PHP.ini configuration for your website or WAMP server.
Here is the detail elaboration of the steps involved.
Step 1: Download the Fake Sendmail for Windows and put the "sendmail" folder undr your WAMP installation path. Since most of you install WAMP under C:\ drive and assuming that move the "sendmail" folder to "C:\wamp\sendmail"
Step 2: Now configure the "sendmail.ini" file which can be found on "C:\wamp\sendmail". Use the below settings for Gmail. You can configure it for other email also. After changing the "sendmail.ini" file, it will look like below:
; configuration for fake sendmail [sendmail] smtp_server=smtp.gmail.com smtp_port=465 smtp_ssl=ssl default_domain=localhost error_logfile=error.log debug_logfile=debug.log firstname.lastname@example.org auth_password=gmailpassword pop3_server= pop3_username= pop3_password= force_sender= force_recipient= hostname=localhost
Step 3: After setting the sendmail configuration, you need to change the setting (if not already done) in your gmail. Login to your gmail account and goto Settings and enable IMAP Access in your GMail’s Settings -> Forwarding and POP/IMAP -> IMAP Access: Enabled
Also go to google account setting -> Sign-in & Security -> Allow Less Secure Apps: turn it On
Step 4: Open php.ini from “C:\wamp\bin\apache\Apache2.4.9\bin” and configure it as following (The php.ini at “C:\wamp\bin\php\php5.3.x” would not work).
[mail function] ; 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:\wamp\sendmail\sendmail.exe -t -i"
Step 5: Restart WAMP Server
Step 6: Create file "testmail.php" under www folder of WAMP and put the below code inside. Change the to and from email.
<?php $to = 'email@example.com'; $subject = 'Testing sendmail feature in WAMP'; $message = 'Hi, you just received an email using sendmail!'; $headers = 'From: firstname.lastname@example.org' . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=utf-8'; if(mail($to, $subject, $message, $headers)) echo "Email sent"; else echo "Email sending failed"; ?>
Congratulations!! You have just send email using sendmail in WAMP.