Trying to send email through PHP mailer from local xampp but getting error:
SMTP -> ERROR: Password not accepted from server: 535-5.7.8 Username and Password not accepted.
SMTP -> ERROR: MAIL not accepted from server: 530-5.5.1 Authentication Required.
The following From address failed: azadlm460#gmail.com : MAIL not accepted from server,530,5.5.1
Code is:
<?php
function sendOTP($clientemail,$num) {
require('phpmailer/class.phpmailer.php');
$message_body = "One Time Password for PHP login authentication is:<br/><br/>" . $num;
$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->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "Azad";
$mail->Password = "mypass";
$mail->SetFrom("myemail");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("anotheremail");
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}
else{
echo "Message has been sent";
}
}
?>
Already tried:
Added PHP mailer in root.
Allow access for less secure apps.
Changed password for gmail.
Account access enabled.
Related
Following is the code that I am using for sending mail using PHPMailer but getting error.
public function changePassword(){
if($this->request->is('post')){
require_once(ROOT .DS. 'vendor' . DS . 'PHPMailer' . DS . 'class.phpmailer.php');
$email = 'abc#gmail.com';
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->isHTML(true);
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$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 = "xyz#gmail.com";
$mail->Password = "dead_gone";
$mail->SetFrom("xyz#gmail.com");
$mail->AddAddress($email);
$mail->Subject = "password recovery";
$mail->Body = "your password is:- sdx_12345 click here to log in <a href ='http://localhost/cake/logins'> click here </a> ";
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "mail sent";
}
}
}
ERROR:
SMTP -> ERROR: AUTH not accepted from server: 530 5.7.0 Must issue a STARTTLS command first. v3sm8416695par.17 - gsmtp
SMTP Error: Could not authenticate. Mailer Error: SMTP Error: Could not authenticate.
This property is case-sensitive:
$mail->SMTPSecure = 'tls'
It would help if you based your code on the gmail example provided with PHPMailer - it's not as if you're the first to connect to gmail!
try a SSL connection over the port 465 and look at you security settings in you account from google
You should also put
$mail->IsHTML(true);
after you set your body and attachments.
Edit:
It also might be possible that TLS has to be lowercase.
I'm using PHPMailer.
But when i upload to my host i get the error SMTP connect() failed.
My environment
1. Server OS:CentOS 7
2. Web Services: XAMPP 5.6.8
3. PHPMailer:5.2.4
this is my code:
<?php
require_once('PHPMailer_old/class.phpmailer.php');
try{
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$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";
$mail->SMTPAutoTLS = false; // close TLS
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "Test#gmail.com"; // GMAIL username
$mail->Password = "Test"; // GMAIpassword
$mail->FromName = "Test Manager";
$mail->From = "Test#gmail.com";
$to = "Test#hotmail.com";
$mail->AddAddress($to);
$mail->Subject = "First PHPMailer Message";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->WordWrap = 80;
$body = "success!";
$mail->MsgHTML($body);
$mail->IsHTML(true);
$mail->Send();
echo "Message has been sent.";
}catch(phpmailerException $e){
echo "Sending Failed";
echo $e -> errorMessage();
}
?>
Error Message In web:
SMTP -> ERROR: Failed to connect to server: (0)
Sending FailedSMTP Error: Could not connect to SMTP host.
Thanks Everyone Help!
My Solution is uninstall XAMPP and respectively install apache, PHP, MySQL
<?php
require '/etc/PHPMailer/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->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "my#gmail.com";
$mail->Password = "password";
$mail->SetFrom("from#gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("to#gmail.com");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
This is my mail functionality code & it gives me the error
SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No address associated with hostname
I don't have extension=php_openssl.dll in my php.ini file but still I've included this and the same issue
To avoid the problem of dynamic IP (every time i ping smtp.gmail.com I see a slight difference in the last 3digit chunk), you just have to use php built-in gethostbyname() to read the IP in real-time.
$smtp_host_ip = gethostbyname('smtp.gmail.com');
Then use that as host.
Hope it helps.
include("class.phpmailer.php");
include("class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "ssl://smtp.gmail.com"; // specify main and backup server
$mail->Port = 465; // set the port to use
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "******#gmail.com"; // your SMTP username or your gmail username
$mail->Password = "******"; // your SMTP password or your gmail password
$from = "***********#example.com"; // Reply to this email
$to="******#gmail.com"; // Recipients email ID
$name=" Name"; // Recipient's name
$mail->From = $from;
$mail->FromName = "Webmaster"; // Name to indicate where the email came from when the recepient received
$mail->AddAddress($to,$name);
$mail->AddReplyTo($from,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Sending Email From Php Using Gmail";
$mail->Body = "This Email Send through phpmailer, This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
am getting this error
SMTP Error: Could not authenticate. Mailer Error: SMTP Error: Could not authenticate.
Since you are using SSL. Add this line of code
$mail->SMTPSecure = 'ssl';
Also change your
$mail->Host = "ssl://smtp.gmail.com";
to
$mail->Host = "smtp.gmail.com";
Also, make sure if you have enabled the extension php_openssl.dll
if you are sure your username and password are correct
then do these steps
1 $mail -> SMTPSecure = 'ssl';
2 $mail->Host = "smtp.gmail.com";
3 https://support.google.com/mail/answer/78754
4 go to google acocunts then connected app and change to less secure apps on
follow all steps in number 3
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)