I'm trying to send an email from my hotmail account using PHPMailer. It's working fine from my PC but when I try it on another PC I get this error message:
2015-04-23 17:31:18 CLIENT -> SERVER: EHLO localhost
2015-04-23 17:31:18 CLIENT -> SERVER: QUIT
2015-04-23 17:31:18 SMTP connect() failed. Mailer Error
Here's my code:
<?php
require "C:\wamp\www\PHPMailer-master\PHPMailerAutoload.php";
$mail = new PHPMailer();
$mail->SMTPSecure = 'SSL';
$mail->Username = "b1sakher#hotmail.fr";
$mail->Password = "rerered";
$mail->AddAddress("b1sakher#hotmail.fr");
$mail->FromName = "My Name";
$mail->Subject = "My Subject";
$mail->Body = "My Body";
$mail->Host = "smtp.live.com";
$mail->Port = 587;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->From = $mail->Username;
if(!$mail->Send())
{
echo "Mailer Error";
}
else
{
echo "Message has been sent";
}
?>
Firstly you should add 'Debugging Mode' to your code, this will tell you where you are going wrong.
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->SMTPDebug = 2; //Alternative to above constant
I had a similar issue, but found out it was the CFS Firewall in Cpanel/WHM blocking the port.
Login into WHM.
Go to ConfigServer Security & Firewall inside plugins option.
Click on Firewall configuration.
Filter by SMTP Settings.
Look for SMTP_ALLOWUSER option and add the Cpanel account username separated by coma.
Restart the firewall.
If you don't have access to WHM ask your hosting provider.
Related
Mail not send to user via SMTP using sendgrid.it shows SMTP error
code
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.sendgrid.net"; // SMTP server
$mail->SMTPSecure = "SSL";
$mail->SMTPAuth = true;
$mail->Username = "szdfsdf";
$mail->Password = "sdfsdfsdfsdf";
$mail->Port = "465";
$mail->From = "tests#gmail.com";
$mail->FromName = "Test";
$mail->AddAddress("test#services.in");
$message = "hi how r u in medapps?";
$message = trim($message);
$mail->Subject = "from test";
$mail->Body = trim($message);
if(!$mail->Send()){
echo "Mailer error: ".$mail->ErrorInfo;
}
else{
echo "Mail triggered to alert the status!";
}
result
Mailer error: SMTP Error: Could not connect to SMTP host.
When connecting to SendGrid via SMTP using API Keys, you need to use apikey as the username.
Also, since you just shared that API Key publicly here, you need to destroy it and make a new one. It's no longer secure.
SendGrid does support port 465 for SSL connectiong, but as Jim said, you need to test your connection and see if your server is allowing that connection. If not, try a different port as recommended on that article.
I would recommend trying port 587 with a TLS connection.
I am really hoping one of you can help me. I've been pulling my hair out for about 2 hours with this. One of the accounts on my client's email servers got compromised and Google start blocking attempts for us to send emails. So I am trying to switch from the basic PHP mail command to PHPMailer and send through Google's SMTP server. This client uses Google Pro for all of his accounts.
I am using the following:
$mail = new PHPMailer();
$mail->isSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->SMTPSecure = "tls"; // sets the prefix to the server
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "no-reply#mydomain.com"; // GMAIL username
$mail->Password = "*********"; // GMAIL password
$mail->SetFrom('no-reply#mydomain.com', 'Jimmy');
$mail->Subject = $this->subject;
$body = $this->message;
//$body = eregi_replace("[\]",'',$body);
$mail->MsgHTML($body);
$mail->AddAddress($this->to, 'bob');
if(!$mail->Send()) {
error_log("Mailer Error: " . $mail->ErrorInfo);
echo '[br /]Fail';
} else {
error_log("Message sent!");
echo '[br /]Pass';
}
I know the credentials are correct because I can login with them. I've done all kinds of stuff to this script and the account it is trying to use to send:
Change from TLS to SSL
'unblock captcha' in the account
disabled 2 factor auth (it was already off)
enabled 'less secure apps'
I'm not sure what else to do. This is the error I keep getting:
2017-05-15 03:12:30 CLIENT -> SERVER: EHLO americanbeautytools.com
2017-05-15 03:12:30 CLIENT -> SERVER: STARTTLS
2017-05-15 03:12:30 CLIENT -> SERVER: EHLO americanbeautytools.com
2017-05-15 03:12:30 CLIENT -> SERVER: AUTH LOGIN
2017-05-15 03:12:30 CLIENT -> SERVER: xxx=
2017-05-15 03:12:30 CLIENT -> SERVER: xxx=
2017-05-15 03:12:32 SMTP ERROR: Password command failed: 535 Incorrect authentication data
2017-05-15 03:12:32 SMTP Error: Could not authenticate.
2017-05-15 03:12:32 CLIENT -> SERVER: QUIT
2017-05-15 03:12:32 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
The part about password command failed is the part I don't get. How can that be wrong when I login with that email account just fine?
I have looked at about 15 of the threads on this topic and none of what they suggest solves my problem. This is a google pro account that my client runs through google so it wouldn't be the 'free' restriction thing.
Test with G-suite account or sendgrid account. I have tested with my gmail credentials it works.
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->Username = 'admin#gmail.com'; // SMTP username
$mail->Password = '123456789'; // SMTP password
$mail->setFrom('admin#gmail.com, 'Krishna');
$mail->addAddress($to_addr, 'Test'); // Add a recipient
$mail->Subject = $subject;
$mail->isHTML(true);
$mail->Body = $message;
Try making a new Gmail account for the sole purpose of this project. I was facing the exact problem, apparently, Google doesn't let the server login to your account from some location very far away.
Creating a new account worked fine for me, hope it helps.
<?php
require ('../PHPMailerAutoload.php'); //add PhPMailerAutoload.php file Path
$mail = new PHPMailer(); // create Object
$name=$_POST['Name']; //get name from post method
$to=$_POST['email']; //get email from post method
$message = $_POST['message']; //get msg from post method
$mail->isSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->SMTPSecure = "ssl"; // sets the prefix to the server
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "no-reply#mydomain.com"; // GMAIL username
$mail->Password = "*********"; // GMAIL password
$mail->SetFrom('no-reply#mydomain.com', 'Jimmy'); //Set who the message is to be sent from
$mail->Subject = "Email from Mailer"; // $this->subject;
$mail->Body = "test Email msg"; // $this->message;
$mail->isHTML(true);
$mail->MsgHTML($message);
$mail->addAddress($to,$name);
$mail->WordWrap = 70;
if(!$mail->Send()) {
echo 'Message could not be sent.'.'<br>';
echo "Mailer Error: " . $mail->ErrorInfo);
exit;
} else {
echo 'Message sent.'.'<br>';
exit;
}
?>
I have been reading some older questions and I haven't found yet the solution to my problem.
Here it goes.
I'm developing a cool website with some mail functions, limited for admin users.
Right now I'm developing the site on localhost, but I've been provided with a Gmail account that will be used for the website.
I've been seeking through the web and the PHPMailer module seems a good election.
My idea is to send emails from my localhost to any other email address using the Gmail account.
Here are the codes I'm using.
For the Apache2.2 server
LoadModule ssl_module modules/mod_ssl.so
For php.ini
[mail function]
SMTP = smtp.gmail.com
smtp_port = 465
sendmail_from = admins.domaing#gmail.com
And the php codes
<?php
date_default_timezone_set("Europe/Madrid");
require_once("class.phpmailer.php");
$mail = new PHPMailer();
$body = 'It works!';
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "admins.domaing#gmail.com";
$mail->Password = "*********";
$mail->SetFrom('admins.domaing#gmail.com', 'Admin');
$mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";
$mail->MsgHTML($body);
$address = "user#email.com";
$mail->AddAddress($address, "user name");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
Actually the error I'm getting is:
Invalid XML: SMTP -> ERROR: Failed to connect to server: (0)
Any suggestions?
Solution from the original poster:
Just change
$mail->Username = "admins.domaing#gmail.com";
to
$mail->Username = "admins.domaing";
I used this coding to send mail using gmail, but am getting the below error, here when i removed the ssl part, its working, but i dint receive any emails(checked inside spam also). Any other problems ?
$mail = new phpmailer;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 1;// enables SMTP debug information (for testing)
$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 = "un"; // GMAIL username
$mail->Password = "pwd"; // GMAIL password
$mail->SetFrom('test#gmail.com', 'Bharanidharan');
$mail->AddReplyTo("test#gmail.com","Vishal Kumar");
$mail->AddAddress("test#gmail.com","Bharani");
$mail->Subject = "Hey, check out";
$body = "hey, check email";
$mail->MsgHTML($body);
$address = "test#gmail.com";
$mail->AddAddress($address, "test");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
Enable the mod_ssl in Apache (search the config file) and the openssl PHP extension (check php.ini)
I tried to use php mailer but errors as follows.
SMTP -> FROM SERVER:
SMTP -> FROM SERVER:
SMTP -> ERROR: EHLO not accepted from server:
SMTP -> FROM SERVER:
SMTP -> ERROR: HELO not accepted from server:
SMTP -> ERROR: AUTH not accepted from server:
SMTP -> NOTICE: EOF caught while checking if connectedSMTP Error: Could not authenticate. Message could not be sent.
Mailer Error: SMTP Error: Could not authenticate.
and my code
<?php
require("class.phpmailer.php")
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPDebug = 2;
$mail->Username = "admin#xxxxxxxxxxxx.in";
$mail->Password = "xxxxxxxx";
$mail->From = "admin#xxxxxxxxxxxx.in";
$mail->FromName = "Mailer";
$mail->AddAddress("xxxx#yahoo.co.in", "mine");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "Here is the subject"
$mail->Body = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send()) {
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
I was getting this due to wrong port for SSL.
SSL = 465
TLS = 587
See:
http://mail.google.com/support/bin/answer.py?hl=en&answer=13287
Some servers (especially shared hosting) will block you from using SSL with SMTP, I had the same problem once.
Either change host if you can, try using the default PHP mail() function or send through another mail server that does not require SSL e.g. port 25 not 465.
Something like AuthSMTP would be your best bet for an alternate mail server.
I had the same problems, it seems that we have
to set the SMPTSecure value.
First I changed the port from 465 to 587 and added:
$mail->SMTPSecure = "tls";
and it worked :)
If you are working in your localhost just go to the PHP Extention and enable or check the php_openssl
it will be able to access the SSL ports.
try this code
require 'PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->IsSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
//$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
//$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 465;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'ssl';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "admin#gmail.com";
//Password to use for SMTP authentication
$mail->Password = "admin123";
$mail->setFrom('admin3#gmail.com', 'development'); //add sender email address.
$mail->addAddress('admins#gmail.com', "development"); //Set who the message is to be sent to.
//Set the subject line
$mail->Subject = $response->subject;
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->Body = 'Name: '.$data['name'].'<br />Location: '.$data['location'].'<br />Email: '.$data['email'].'<br />Phone:'.$data['phone'].'<br />ailment: '.$data['ailment'].'<br />symptoms: '.$data['symptoms'];
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.gif');
//$mail->SMTPAuth = true;
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
Had the same issue, Change port No in opencart mail setting to 587 and works fine
May be because of fire wall?
If you can't sign in to Google Talk,
or you're receiving an error that
says, Could not authenticate to
server, check if you have personal
firewall software installed, or if
your computer is behind a proxy server
that requires a username and password.
http://www.google.com/support/talk/bin/answer.py?hl=en&answer=30998
I use the same script for several clients and only run into this problem when deploying to Amazon EC2 cloud providers (such as Openshift).
These are tried and tested settings in phpmailer:
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587;
'but' Google blocks these services as an 'anti-spam' / political maneuver, and this has caught me out because it works locally and on most hosting providers, there is nothing much you can do when they don't accept outbound messages from your hosts DNS / IP. Accept it and move on by looking for another smtp server to route messages through.
not sure but try $mail->Host = "smtp.gmail.com" =>$mail->Host = "smtp.google.com"