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:
- Open hMailServer Administrator.
- Click the "Add domain ..." button to create a new domain.
- Under the domain text field, enter your computer's localhost IP.
- Example: 127.0.0.1 is your localhost IP.
- Click the "Save" button.
- Now go to Settings > Protocols > SMTP and select the "Delivery of Email" tab.
- Find the localhost field enter "localhost".
- Click the Save button.
Configure your Gmail account, perform following modification:
- Go to Settings > Protocols > SMTP and select "Delivery of Email" tab.
- Enter "smtp.gmail.com" in the Remote Host name field.
- Enter "465" as the port number.
- Check "Server requires authentication".
- Enter your Google Mail address in the Username field.
- Enter your Google Mail password in the password field.
- Check mark "Use SSL"
- 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:
- Go to Settings > Advanced > IP Ranges and double click on "My Computer" which
should have IP address of 127.0.0.1 - Check the Allow Deliveries from External to External accounts Checkbox.
- 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
Sending Bcc Emails Using a Smtp Server
How to Strip Out the Domain Name from a Url in PHP
Yii2 Require All Controller and Action to Login
Does the Condition After && Always Get Evaluated
How to Use PHPunit to Test a Function If That Function Is Supposed to Kill PHP
How to Check If a Value Already Exists to Avoid Duplicates
PHP Switch Case Statement to Handle Ranges
Detect Mobile Devices - and Tablet Devices
Using Curl in PHP with Client Certificate and Private Key in Separate Files
How to Use SQL Server Connection in Laravel
Unit Testing with Items That Need to Send Headers
Extending Sonata User Bundle and Adding New Fields
Change the PHP Path to Mamps PHP
Using Prepared Statement, How I Return the Id of the Inserted Row
Laravel Error: Method Illuminate\View\View::_Tostring() Must Not Throw an Exception
How to Convert Between Time Zones in PHP Using the Datetime Class