Sending Emails with Wamp

How to send email from localhost WAMP Server to send email Gmail Hotmail or so forth?

Configuring a working email client from localhost is quite a chore, I have spent hours of frustration attempting it. At last I have found this way to send mails (using WAMP, XAMPP, etc.):

Install hMailServer

Configure this hMailServer setting:

  1. Open hMailServer Administrator.
  2. Click the "Add domain ..." button to create a new domain.
  3. Under the domain text field, enter your computer's localhost IP.

    • Example: 127.0.0.1 is your localhost IP.
  4. Click the "Save" button.
  5. Now go to Settings > Protocols > SMTP and select the "Delivery of Email" tab.
  6. Find the localhost field enter "localhost".
  7. Click the Save button.

Configure your Gmail account, perform following modification:

  1. Go to Settings > Protocols > SMTP and select "Delivery of Email" tab.
  2. Enter "smtp.gmail.com" in the Remote Host name field.
  3. Enter "465" as the port number.
  4. Check "Server requires authentication".
  5. Enter your Google Mail address in the Username field.
  6. Enter your Google Mail password in the password field.
  7. Check mark "Use SSL"
  8. Save all changes.

Optional

If you want to send email from another computer you need to allow deliveries from External to External accounts by following steps:

  1. Go to Settings > Advanced > IP Ranges and double click on "My Computer" which
    should have IP address of 127.0.0.1
  2. Check the Allow Deliveries from External to External accounts Checkbox.
  3. Save settings using Save button.

Sending mail via php script using wamp server

You can use PHPMailer or PHPMimeMail to send mail from your localhost to gmail. To send email to gmail, you should send authenticated mail like SMTP mail. You should configure your mail username,password, and your mail host in your mail configurtion.

sample PHPmailer script for Gmail :

require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail = new PHPMailer();

$body = file_get_contents('contents.html');
$body = preg_replace('/[\]/','',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "mail@gmail.com"; // GMAIL username
$mail->Password = "12345"; // GMAIL password

$mail->SetFrom('mail@gmail.com', 'Balaji K');

$mail->AddReplyTo("mail2@gmail.com");

$mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);
$mail->Body($body);
$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");

$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

(WAMP/XAMP) send Mail using SMTP localhost

You can use this library to send email ,if having issue with local xampp,wamp...

class.phpmailer.php,class.smtp.php
Write this code in file where your email function calls

    include('class.phpmailer.php');

$mail = new PHPMailer();
$mail->IsHTML(true);
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "your email ID";
$mail->Password = "your email password";
$fromname = "From Name in Email";

$To = trim($email,"\r\n");
$tContent = '';

$tContent .="<table width='550px' colspan='2' cellpadding='4'>
<tr><td align='center'><img src='imgpath' width='100' height='100'></td></tr>
<tr><td height='20'> </td></tr>
<tr>
<td>
<table cellspacing='1' cellpadding='1' width='100%' height='100%'>
<tr><td align='center'><h2>YOUR TEXT<h2></td></tr/>
<tr><td> </td></tr>
<tr><td align='center'>Name: ".trim(NAME,"\r\n")."</td></tr>
<tr><td align='center'>ABCD TEXT: ".$abcd."</td></tr>
<tr><td> </td></tr>
</table>
</td>
</tr>
</table>";
$mail->From = "From email";
$mail->FromName = $fromname;
$mail->Subject = "Your Details.";
$mail->Body = $tContent;
$mail->AddAddress($To);
$mail->set('X-Priority', '1'); //Priority 1 = High, 3 = Normal, 5 = low
$mail->Send();


Related Topics



Leave a reply



Submit