I am trying to send an email using PHPMailer and from my gmail account. But it shows
SMTP ERROR: Password command failed: 535-5.7.8 Username and Password
not accepted. Learn more at535 5.7.8
https://support.google.com/mail/?p=BadCredentials
5-20020aca0605000000b0037d8d231f8csm951314oig.51 - gsmtp SMTP Error:
Could not authenticate.
Unfortunately, the option to use "less secure apps" has been turned off by Google, so that option is not available to me. What are some other options I can try to resolve this issue?
Here is my current script:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'lsurahman157#gmail.com'; // SMTP username
$mail->Password = 'mypasswodis!'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('lsurahman157#gmail.com', 'Full Name');
$mail->addAddress('aonik1#lsu.edu', 'Abdur Rahman Onik'); // Add a recipient
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Subject Text';
$mail->Body = '<i>Mail body in HTML</i>';
$mail->AltBody = 'This is the plain text version of the email content';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
If you activate MFA for your account, you are able to define App-Passwords. You can use the passwords for SMTP an IMAP authentication.
Related
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 this script to send mails with Gmail SMTP:
require 'mailPhp/PHPMailerAutoload.php';
$email= $_POST['Email'];
echo $email;
$clientFolder= $GLOBALS['directory'];
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#gmail.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable encryption, 'ssl' also accepted
$mail->Port = 465; //Set the SMTP port number - 587 for authenticated TLS
$mail->setFrom('contact#azura-space.com', 'Fuyor Romania'); //Set who the message is to be sent from
$mail->addReplyTo('contact#bocher.us', 'Comenzi Fuyor Romania'); //Set an alternative reply-to address
$mail->addAddress("$email"); // Add a recipient
$mail->WordWrap = 50; // Set word wrap to 50 characters
// $mail->addAttachment('/usr/labnol/file.doc'); // Add attachments
$mail->addAttachment("$clientFolder/file.pdf", 'DeliveryOrder.pdf');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Comanda Fuyor';
$mail->Body = 'Va multumim ca ati cumparat de la noi. V-am trimis o copie
dupa comanda dvs in acest mail.';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
This is working fine if it runs from an HTTP domain, but when I put it on an https domain it gives me this error:
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Also, I tried to change the secure method and port from TLS 587 to SSL 465 but is not working. The script is identical on both domains...
Where is the problem?
date_default_timezone_set('Etc/UTC');
require 'phpmailer/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';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "username#gmail.com";
//Password to use for SMTP authentication
$mail->Password = "mypassword";
//Set who the message is to be sent from
$mail->setFrom('username#gmail.com', 'User');
//Set an alternative reply-to address
//Set who the message is to be sent to
$mail->addAddress($email,$name);
//Set the subject line
$mail->Subject = 'Subject';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$body = "body";
$mail->msgHTML($body);
//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.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
I tried with ports 465 and 587. No access to php.ini file and also tried setting timeout limit. No go. openssl is enabled.
Checked with:
<?php echo (extension_loaded('openssl')?'SSL loaded':'SSL not loaded')."\n"; ?>
I always get the same error:
SMTP ERROR: Failed to connect to server: Connection timed out (110)
SMTP connect() failed.
Mailer Error: SMTP connect() failed
I want to send a confirmation mail to an user who is trying to register. Iam using PHP Mailer for sending mails. Here is my code:
require_once("PHPMailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPAuth = true;// turn on SMTP authentication
$mail->Username = "root";// SMTP username
$mail->Password = "";// SMTP password
$mail->SetLanguage("en","PHPMailer/language");
//compose mail
$mail->From = "admin#localhost.com";
$mail->FromName = "Cinema Admin";
$mail->AddAddress($_POST['email']);
$mail->AddReplyTo("admin#localhost.com", "Cinema Admin");
$mail->Subject = 'Your confirmation link here';
$mail->Body = "Your confirmation link\r\n";
$mail->Body .= "Click on this link to activate your sccount\r\n";
$mail->Body .= "http://localhost/user.login_plugin/confirm.php?passkey=$confirm_code";
//send mail
if (!$mail->Send())
{
echo "Message was not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
When I execute the file,it says
Message was not sent
Mailer Error: SMTP connect() failed.
Could anyone suggest me for sending mails from localhost to the registered user's emailid.
I had searched with few titles regarding "ending emails" in stack overflow, but couldn't find any solution from any posts.
Thank You in advance
Could you try remove the smtp part? From your comment , you do not have mail server setup.
$mail = new PHPMailer();
$mail->SetLanguage("en","PHPMailer/language"); // remove smtp things
You must need a SMTP details in order to send an email using SMTP, For example if you want to setup SMTP using gmail,
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "yourusername#gmail.com"; // GMAIL username
$mail->Password = "yourpassword"; // GMAIL password
If you don't want use SMTP, you can called default mail function
$mail->IsMail(); //Sets Mailer to send message using PHP mail() function.
so i have been working with gmail and using php mailer and it was working fine.
i tried to do the same with yahoo mail but it doent seem to work.
i have tried various ports and settings but it isnt working.
here is the code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>PHPMailer - GMail SMTP test</title>
</head>
<body>
<?php
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require 'phpmailer/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.mail.yahoo.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587; //995 and 465 port tried but not working
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tsl';//only ssl tried not working
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "sender#yahoo.com";
//Password to use for SMTP authentication
$mail->Password = "sender_pass";
//Set who the message is to be sent from
$mail->setFrom('sender_#yahoo.com', 'sender_name');
//Set who the message is to be sent to
$mail->addAddress('receiver#yahoo.com', 'receiver_name');
//Set the subject line
$mail->Subject = 'PHPMailer YMail SMTP test';
$mail->msgHTML(file_get_contents('phpmailer/examples/contents.html'), dirname(__FILE__));
$mail->AltBody = 'This is a plain-text message body';
$mail->addAttachment('phpmailer/examples/images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
</body>
</html>
and i get the following error:
SERVER -> CLIENT: 220 smtp.mail.yahoo.com ESMTP ready
CLIENT -> SERVER: EHLO localhost
CLIENT -> SERVER: AUTH LOGIN
SERVER -> CLIENT: 530 5.7.0 Must issue a STARTTLS command first
CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 2.0.0 Bye
SMTP connect() failed.
Mailer Error: SMTP connect() failed.
The correct is tls, you have a spell mistake:
$mail->SMTPSecure = 'tls'
2020 - Google brought me here for something similar.
Finally got phpmailer working with yahoo.
My Findings:
* Ports -> Both ssl/465 and tls/587 work with Yahoo. You dont have to
worry about that.
* From Address -> Cannot be something arbitrary, just use your
yahoo account email here
* ReplyTo Address -> This too must be a valid yahoo account
or you may leave this blank.
And ...
for programmatic usage of yahoo with phpmailer, you need to use another passwd ( not the password that you use to login manually via the web - got this tip from a non stackoverflow site, maybe expert xchange? ). This password is called the App Password. You have to generate it from inside your account.
Account Info -> Account Settings -> Manage Your App Passwords
-> Select Other App -> Key in 'AutoMailer'
or anything you like and generate the passwd - Its a 4 word passwd.
Use this passwd in your phpmailer script.
Everything should be fine now.
The yahoo SMTP host is: smtp.mail.yahoo.fr, the port: 465 and SSL is required.
So with PHPMailer:
$mail->Host = "smtp.mail.yahoo.fr, ";
$mail->Username = "youryahooadd#yahoo.fr";
$mail->Password = "youryahoopw";
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail = new PHPMailer();
$body = "<h1>hello, world!</h1>"
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.mail.yahoo.com"; // sets YAHOO as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "yourusername#gmail.com"; // GMAIL username
$mail->Password = "yourpassword"; // GMAIL password
$mail->SetFrom('name#yourdomain.com', 'First Last');
$mail->AddReplyTo("name#yourdomain.com","First Last");
$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);
$address = "whoto#otherdomain.com";
$mail->AddAddress($address, "John Doe");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}