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.
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/
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!";
}
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
unable to send email using php on wamp server
Here is how I got hMailer to work with my WAMPServer's PHP
First setup your hmailer server.
- Create a domain, lets call it testmail.net
- Create an account that has no password attached to it, lets say nopwd@testmail.net
- Create an account that is set up as a Catch-all lets say postmaster@testmail.net. Using this you dont have to create an account for every user you want to send mail to and then login as that user, all mail comes to this account.
Now add your mail server domain name to the HOSTS file
Edit c:\windows\system32\drivers\etc\hosts and add a line like this
127.0.0.1 testmail.net
If you are running the mail server on another PC use the IP of the other PC instead of 127.0.0.1
Change the php.ini file ( use the wampmanager icon menus to make sure you are editing the correct php.ini )
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = mail.testmail.net
; http://php.net/smtp-port
; assuming you are using the standard port number, change if you used something else.
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = nopwd@testmail.net
Now just make sure that you also use the from address when you send mail as the hmailer will want this or it will probably reject the email.
$to = 'xyz@testmail.net';
$subject = 'Customer_Details Report';
$msg="php mail";
$headers = 'From: nopwd@testmail.net' . "\r\n"
$result=mail($to, $subject, $msg, $headers);
Related Topics
Laravel Error: Method Illuminate\View\View::_Tostring() Must Not Throw an Exception
Php: Whats the Total Length of a Post Global Variable
How to Check If a File Exists on a Remote Server Using PHP
Concat Columns with Laravel 5 Eloquent
Split an Array into N Arrays - PHP
Prevent Session Expired in PHP Session for Inactive User
PHP Password_Hash and Password_Verify Issues No Match
PHP E-Mail Form Sender Name Instead of E-Mail
How to Connect to Database on Another Server
Best Way to Parse an Invalid HTML in PHP
PHP Check If Time Is Between Two Times Regardless of Date
PHP Domdocument Error Handling
Move an Array Element to a New Index in PHP
Allow Users to Download Files Outside Webroot
Symfony 2 Load Different Template Depending on User Agent Properties