0

I got this error using PHPMailer:

SMTP Error: Could not authenticate. Mailer Error: SMTP Error: Could not authenticate.

and Here is the code :

function send_email($reciever = "e.salamati.taba@gmail.com", $mail_arr = '') { // This function will be upgraded later
$mail = new PHPMailer();
$body = $mail_arr['body'];
//$body = eregi_replace("[\]", '', $body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = true;
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$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 = "user"; // GMAIL username
$mail->Password = "pass"; // GMAIL password
$mail->SetFrom('e.salamati.taba@gmail.com', 'no-reply gmail.com');
$mail->Subject = $mail_arr['subject'];
$mail->MsgHTML($body);
echo "-----------------------";
$address = $reciever;
$mail->AddAddress($address, "e.salamati.taba@gmail.com");

if(! $mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

}

I have also see this, but still got the error, Is there any xampp config or something that cause the problem? Thanks in advance...

Community
  • 1
  • 1
Ehsan
  • 3,964
  • 5
  • 37
  • 58
  • 1
    Set the SMTP debug level to 1 to see errors – Pekka Feb 15 '12 at 13:17
  • I set that to 2 and here are the errors: SMTP -> FROM SERVER:421 Cannot connect to SMTP server 74.125.65.108 (74.125.65.108:465), connect error 10060 SMTP -> FROM SERVER: SMTP -> ERROR: EHLO not accepted from server: SMTP -> FROM SERVER: SMTP -> ERROR: HELO not accepted from server: SMTP -> ERROR: AUTH not accepted from server: SMTP -> NOTICE: EOF caught while checking if connectedSMTP Error: Could not authenticate. Mailer Error: SMTP Error: Could not authenticate. – Ehsan Feb 15 '12 at 13:18
  • does your SMTP server goes with out? probably the auth is not valid or is not set.. – tomexsans Feb 15 '12 at 13:21
  • I have already chose my host smtp.gmail.com should I config anything else for the smtp server, I can also ping smtp.gmail.com – Ehsan Feb 15 '12 at 13:26
  • 2
    You need SSL support on your PHP installation. See this answer another question which is the same as yours: http://stackoverflow.com/a/5709799/825789 – bfavaretto Feb 15 '12 at 13:30
  • possible duplicate of [PHPMailer: SMTP Error: Could not connect to SMTP host](http://stackoverflow.com/questions/3477766/phpmailer-smtp-error-could-not-connect-to-smtp-host) – bfavaretto Feb 15 '12 at 13:31
  • Actually I have uncommented that and reset my xampp but still no use:( – Ehsan Feb 15 '12 at 13:31
  • Take a look at this thread also: http://stackoverflow.com/questions/7713701/codeigniter-ssl-tls-smtp-auth-email-from-phpmailer-code – bfavaretto Feb 15 '12 at 13:33
  • GMail SMTP SSL port is **465** not **587** Also you need to use your full email address to authenticate. i.e. if my email address is `exampleaddress123@gmail.com` I authenticate with that and not just `exampleaddress123` – Flukey Feb 15 '12 at 13:34
  • Non of them is working:(( could you please send me a code which is working for you guys? I'm really confused I have done all the things you said... – Ehsan Feb 16 '12 at 15:54
  • Finally I found that there was two problems first I should wrote the 'tls' in capital letters, and I changed some configs in php.ini like I uncomment the extension=php_smtp.dll – Ehsan Feb 16 '12 at 16:02

0 Answers0