Sandip Armal Patil Sandip Armal Patil - 2 months ago 12
PHP Question

Sending Mail in PHP : SMTP Error: could not authenticate

I am trying to send mail in

PHP
. I use same code for localhost and server. But when I use the code on server, it doesn't seem to work:

SMTP Error: Could not authenticate. Message was not sent.Mailer error: SMTP Error: Could not authenticate.


Here is my code for your reference.

require("class.phpmailer.php"); // path to the PHPMailer class

$mail = new PHPMailer();

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "myname"; // SMTP username
$mail->Password = "password"; // SMTP password

$mail->From = "me@gmail.com";
$mail->AddAddress("sample@gmail.com");

$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;

if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}


I've done lots of searching, nothing pops up. Any help would be greatly appreciated.

Answer

It happen because Password contain special character. I tried using "\"before special character like Password="djgh\^dfgfjk". But it didn't help me.
I just create new id and simple password without any special character and amazingly it's work.
Use password with out special character.

Comments