Wednesday, August 10, 2011

Send Email using WAMP Server

This article is also available at Please visit it for the latest updates on this article.

When building professional web applications, it is very necessary to test email functionality before deploying the website. It is therefore a requirement for web developers to send emails from their development machine during development process.

After tweaking with the Apache and PHP's INIs, I succeeded in sending email from my WAMP server.

So, to use PHP Mailer with GMail, ensure the following:
  • IMAP Access is enabled in your GMail's Settings -> Forwarding and POP/IMAP -> IMAP Access:

  • "ssl_module" module in Apache server is enabled:

  • "php_openssl", "php_smtp" and "php_sockets" extensions for PHP compiler are enabled:

I used the following code in PHP file:

require 'class.phpmailer.php';
$mail = new PHPMailer();
$mail->PluginDir = './PHPMailer_5.2.0'; // relative path to the folder where PHPMailer's files are located
$mail->Port = 465;
$mail->Host = ''; // "ssl://" didn't worked
$mail->IsHTML(true); // if you are going to send HTML formatted emails
$mail->Mailer = 'smtp';
$mail->SMTPSecure = 'ssl';

$mail->SMTPAuth = true;
$mail->Username = "";
$mail->Password = "your_gmail_password";

$mail->SingleTo = true; // if you want to send mail to the users individually so that no recipients can see that who has got the same email.

$mail->From = "";
$mail->FromName = "Your Name";

$mail->addAddress("","User 1");
$mail->addAddress("","User 2");

$mail->addCC("","User 3");
$mail->addBCC("","User 4");

$mail->Subject = "Testing PHP Mailer with localhost";
$mail->Body = "Hi,<br /><br />This system is working perfectly.";

    echo "Message was not sent <br />PHP Mailer Error: " . $mail->ErrorInfo;
    echo "Message has been sent";

To use PHP Mailer on actual online server, you will need to change some of the configurations of PHP Mailer as described on the cPanel like control panel on your actual online server. These configurations would be:
  • $mail->Port
  • $mail->Host
  • $mail->Mailer
  • $mail->SMTPSecure
  • $mail->Username
  • $mail->Password
  • $mail->From
  • $mail->FromName