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.
How to configure WAMP (localhost) to send email using Gmail?
Gmail servers use SMTP Authentication under SSL or TLS. I think that there is no way to use the mail()
function under that circumstances, so you might want to check these alternatives:
- PEAR::Mail
- phpMailer
- Nette\Mail
They all support SMTP auth under SSL.
You'll need to enable the php_openssl
extension in your php.ini.
Additional Resources:
- How to Send Email from a PHP Script Using SMTP Authentication (using
PEAR::Mail
) - Send email using PHP with Gmail (using phpMailer)
- Mailing using
Nette\Mail
(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();
Configure WAMP server to send email
Configuring a working email client from localhost is quite a chore, I have spent hours of frustration attempting it. I'm sure someone more experienced may be able to help, or they may perhaps agree with me.
If you just want to test, here is a great tool for testing mail locally, that requires almost no configuration:
http://www.toolheap.com/test-mail-server-tool/
It worked right off the bat for me, hope this helps you.
Related Topics
Php, Display Image with Header()
Echo a Multidimensional Array in PHP
PHP File Listing Multiple File Extensions
When to Use HTMLspecialchars() Function
Is It Okay to Use Array[Key] in PHP
Using Wildcards in Prepared Statement - MySQLi
Fix Access Denied for User 'Root'@'Localhost' for PHPmyadmin
Mechanisms for Tracking Db Schema Changes
Include Constant in String Without Concatenating
Php: Check If a File Is Loaded Directly Instead of Including