Sandip Armal Patil
Sandip Armal Patil

Reputation: 5905

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 = "[email protected]";
$mail->AddAddress("[email protected]");

$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.

Upvotes: 0

Views: 20203

Answers (5)

Krishnadas PC
Krishnadas PC

Reputation: 6519

It can happen due to various reasons. In my case it worked by changing from

$phpmailer->isSMTP();

to

$phpmailer->Mailer     = 'smtp';

worked.

Upvotes: 0

Sandip Armal Patil
Sandip Armal Patil

Reputation: 5905

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.

Upvotes: 0

jfoucher
jfoucher

Reputation: 2281

Some hosting providers, such as 1and1 block outgoing email ports, such as 25, 465 and 587. The only solution AFAIK is to change hosting provider.

Try making a simple php file that just does a "fsokopen" to the port you are trying to use, and see if that works

Upvotes: 0

transilvlad
transilvlad

Reputation: 14532

Try TLS and port 587:

$mail->SMTPSecure = "tls";
$mail->Host       = "smtp.gmail.com";
$mail->Port       = 587;

As you can see you could also specify that you want SSL connection in the SMTPSecure variable and just use the host as smtp.gmail.com

Also try replacing this $mail->IsSMTP(); with this $mail->Mailer = "smtp";

Upvotes: 2

vishal patel
vishal patel

Reputation: 71

just check this out it may be helpful:
it's telnet for smtp connection working or not? In windows 7 firewall blocked(default) smtp connection so, http://support.microsoft.com/kb/153119

Upvotes: 0

Related Questions