I readly feel confused why i test many many example and correct example to send email with php mailer with gmail account but it did not work,here is the error
> 2015-04-21 07:06:50 CLIENT -> SERVER: EHLO www.ariarules.com
2015-04-21 07:06:50 CLIENT -> SERVER: STARTTLS
2015-04-21 07:06:50 CLIENT -> SERVER: EHLO www.ariarules.com
2015-04-21 07:06:50 CLIENT -> SERVER: AUTH LOGIN
2015-04-21 07:06:50 CLIENT -> SERVER:
2015-04-21 07:06:52 SMTP ERROR: Username command failed:
535 Incorrect authentication data
2015-04-21 07:06:52 SMTP Error: Could not authenticate.
2015-04-21 07:06:52 CLIENT -> SERVER: QUIT
2015-04-21 07:06:52 SMTP connect() failed.
Mailer Error: SMTP connect() failed.
and my code
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 587; // or 587
$mail->IsHTML(true);
$mail->Username = "googleaccount#gmail.com";
$mail->Password = "pass";
$mail->SetFrom("user#gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("user#gmail.com");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
at end it's better to know i test tls & ssl with port 465 & 587 but....
enable "Access for less secure apps" :
https://www.google.com/settings/security/lesssecureapps
gmail does not allow to send emails from less secured applications. there is an option 'access for less secured apps' in google account settings. turn that on and you will be able to send emails.
i was facing same issue some days before . i found this solution , may be it works for you.Pass your values like this. its strange but worked for me.
$username="googleaccount#gmail.com";
$password="pass":
$mail->Username = $username;
$mail->Password = $password;
Related
Since my account on AWS is at sandbox so I created two email addresses in aws and verified them. Then I created SMTP credentials. I have used the credentials in my PHP mailer function but it keeps on saying Couldn't connect to the SMTP host. No idea what I am doing wrong here. One thing more here is that If I use Cpanel or any other SMTP settings instead of aws then this script works which means there is nothing wrong with the script.
Phpmailer function
function sendMail($data){
$mail = new PHPMailer(true);
try {
//Server settings
// $mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = MAIL_HOST; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = MAIL_USERNAME; // SMTP username
$mail->Password = MAIL_PASSWORD; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->setFrom(MAIL_FROM, MAIL_NAME);
$mail->addAddress($data['to'],$data['name']);
$mail->addReplyTo(MAIL_REPLYTO);
// $mail->addCC('cc#example.com');
//$mail->addBCC('bcc#example.com');
$mail->isHTML(true);
$mail->Subject = $data['subject'];
$mail->Body = $data['message'];
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
$array['code'] = 200;
$array['msg'] = "success";
return $array;
} catch (Exception $e) {
$array['code'] = 201;
$array['msg'] = $mail->ErrorInfo;
return $array;
}
}
Error:
We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
<br>
2021-02-19 08:55:59 CLIENT -> SERVER: EHLO domain.com
<br>
2021-02-19 08:55:59 SERVER -> CLIENT: 250-ip-172.xx.xx.xxx.sysadmin.info Hello domain.com [172.xx.xx.xxx]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250-STARTTLS250 HELP
<br>
2021-02-19 08:55:59 CLIENT -> SERVER: STARTTLS
<br>
2021-02-19 08:55:59 SERVER -> CLIENT: 220 TLS go ahead
<br>
SMTP Error: Could not connect to SMTP host.
<br>
2021-02-19 08:55:59 CLIENT -> SERVER: QUIT
<br>
2021-02-19 08:55:59
<br>
2021-02-19 08:55:59
<br>
On the terminal, I did this as well to check if the port is open
Nmap -p587 IP
Result:
Host is up (0.00036s latency).
PORT STATE SERVICE
587/tcp open submission
If I put this command
telnet email-smtp.us-east-1.amazonaws.com 587
telnet email-smtp.us-east-1.amazonaws.com 25
It says
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
No idea why I am not able to send an email from the script to my verified email address. Please help
Here's my settings that work for me:
.......
.......
$port = 587;
.......
.......
$mail = new PHPMailer(true);
try {
// Specify the SMTP settings.
$mail->isSMTP(true);
$mail->setFrom($sender, $senderName);
$mail->Username = $usernameSmtp;
$mail->Password = $passwordSmtp;
$mail->Host = $host;
$mail->Port = $port;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
//$mail->addCustomHeader('X-SES-CONFIGURATION-SET', $configurationSet);
.......
.......
PS: make sure you have the following things in order:
If you're using port 465, change the value of SMTPSecure to ssl.
Check if your instance is able to send outbound requests through these ports.
The user needs an IAM role to be able to send emails through.
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 want to know where the problem is because I get authentication error.
I already have a few gmail accounts,
I created a new one for my website,
I added a new email in "Account and import" to my old gmail account.
I copied my new email username and password to phpmailer code
include_once('phpmailer/class.phpmailer.php');
include_once('phpmailer/class.smtp.php');
//6nb5Drv;
function sendmail(){
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com"; // specify main and backup server
$mail->Port = 587; // Set the SMTP port i tried and 457
$mail->Username = 'newmail#gmail.com'; // SMTP username
$mail->Password = 'newmailpass'; // SMTP password
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->From = 'from#yahoo.com';
$mail->FromName = 'From';
$mail->AddAddress('to#gmail.com', 'To'); // Add a recipient
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <strong>in bold!</strong>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
}
sendmail();
But I get an authentication error.
What is wrong?
Probably something with the credentials, how do I configure gmail smtp?
Debug report:
2015-12-04 17:56:15 CLIENT -> SERVER: EHLO www.site.co
2015-12-04 17:56:15 CLIENT -> SERVER: STARTTLS 2015-12-04
17:56:15 CLIENT -> SERVER: EHLO www.site.co 2015-12-04
17:56:15 CLIENT -> SERVER: AUTH LOGIN 2015-12-04 17:56:15 CLIENT ->
SERVER: UHJlZGljdG9sb2d5 2015-12-04 17:56:15 CLIENT -> SERVER:
U2dHZlB0VHZUbTZ1SW9ZMi1qTlNCQQ== 2015-12-04 17:56:17 SMTP ERROR:
Password command failed: 435 4.7.8 Error: authentication failed:
UGFzc3dvcmQ6 2015-12-04 17:56:17 SMTP Error: Could not authenticate.
2015-12-04 17:56:17 CLIENT -> SERVER: QUIT 2015-12-04 17:56:17 SMTP
connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message
could not be sent.Mailer Error: SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
According to this post:
PHPMailer - SMTP ERROR: Password command failed when send mail from my server, in some case, you have to specify google that this is not a suspicious activity and activate some less secure option in your account.
Assuming this is the right password...
<?php
require_once ("PHPMailer-master/PHPMailerAutoload.php");
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
//$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "abc#gmail.com";
$mail->Password = "abcpassword";
$mail->SetFrom("abc#gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("sameone#domain.com");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
I got the message:
2015-07-11 08:06:17 CLIENT -> SERVER: EHLO action.ticambodia.org
2015-07-11 08:06:17 CLIENT -> SERVER: AUTH LOGIN
2015-07-11 08:06:17 CLIENT -> SERVER: c29lbmdrYW5lbEBnbWFpbC5jb20=
2015-07-11 08:06:17 CLIENT -> SERVER: a2FuZWxAbjB3 2015-07-11 08:06:17 SMTP ERROR: Password command failed: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 mg19sm5958238oeb.10 - gsmtp
2015-07-11 08:06:17 SMTP Error: Could not authenticate.
2015-07-11 08:06:17 CLIENT -> SERVER: QUIT
2015-07-11 08:06:17 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
anyone,could help to find out what is the problem and how to solve it?
The error is from the Google side. For security reasons, Google Blocks less secure apps from accessing your Mails. But you can turn off this.
Sign in with "abc#gmail.com" from your browser.
Go to Allow less secure apps
Click 'Turn On' Radio button.
Now check. You can able to send E-mails
I would like to send an email using Gmail SMTP server through PHP Mailer.
I am running Zend Server Community Edition in my machine.
Following is my code (edited to hide certain confidential information).
require_once('phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$body = "test msg";
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = "587";
$mail->Username = "<valid-id>";
$mail->Password = "<valid-password>";
$mail->SetFrom('a#b.c', 'Name');
$mail->AddReplyTo("a#b.c","Name");
$mail->Subject = "subject";
$mail->MsgHTML($body);
$address = "d#e.f";
$mail->AddAddress($address, "halo:);
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message sent!";
}
Despite following thoroughly the example from PHP Mailer wiki page, I somehow couldn't manage to send the email accordingly.
This is the error message generated by the function:
SMTP -> ERROR: Failed to connect to server: A connection attempt
failed because the connected party did not properly respond after a
period of time, or established connection failed because connected
host has failed to respond. (10060) The following From address failed:
a#b.c Mailer Error: The following From address failed: a#b.c
Please advise me regarding this matter. Thank you.
have you tried:
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = "465";
I have changed in your code my emails, my smtp user, my settings ^^^, password and the line:
$mail->AddAddress($address, "Mihai"); // you forgot a quote
used PHPMailer5.2.1 and result:
SMTP -> FROM SERVER:220 mx.google.com ESMTP gq2sm2073759bkc.13
SMTP -> FROM SERVER: 250-mx.google.com at your service, [***.***.***.***] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH 250 ENHANCEDSTATUSCODES
SMTP -> FROM SERVER:250 2.1.0 OK gq2sm2073759bkc.13
SMTP -> FROM SERVER:250 2.1.5 OK gq2sm2073759bkc.13
SMTP -> FROM SERVER:354 Go ahead gq2sm2073759bkc.13
SMTP -> FROM SERVER:250 2.0.0 OK 1345113839 gq2sm2073759bkc.13
Message sent!
Mail received:
X-Mailer: PHPMailer 5.2.1 (http://code.google.com/a/apache-extras.org/p/phpmailer/)