Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am using PHPMailer to send a basic form to an email address but I get the following error:

SMTP Error: Could not authenticate. Message could not be sent. Mailer Error: SMTP Error: Could not authenticate. SMTP server error: VXNlcm5hbWU6

The weird thing is that if I try to send it again, IT WORKS! Every time I submit the form after that first error it works. But if I leave it for a few minutes and then try again I get the same error again.

The username and password have to be right as sometimes it works fine. I even created the following (very basic) script just to test it and I got the same result

<?php

require("phpmailer/class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();
$mail->Host = "smtp.host.com";
$mail->SMTPAuth = true;
$mail->Username = "mail@mail.com";
$mail->Password = "password";

$mail->From = "mail@mail.com";
$mail->FromName = "From Name";
$mail->AddAddress("mail@mail.com");
$mail->AddReplyTo("mail@mail.com");

$mail->IsHTML(true);  

$mail->Subject = "Here is the subject";
$mail->Body    = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";

?>

I don't think this is relevant, but I just changed my hosting to a Linux shared server. Any idea why this is happening?

Thanks!

***UPDATED 02/06/2012
I've been doing some tests. The results:

I tested the script in an IIS server and it worked fine. The error seems to happen only in the Linux server.

Also, if I use the gmail mail server it works fine in both, IIS and Linux.

Could it be a problem with the configuration of my Linux server??

***UPDATE 2
I tried swiftmail and it works fine :-) so I am dumping PHPMailer

share|improve this question

2 Answers 2

You might try requesting a TLS connection like this:

$mail->SMTPAuth   = true;
$mail->SMTPSecure = "tls";

this question/answer on SO has more information. Including the recommendation to use the php PEAR library instead of phpmailer.

share|improve this answer
    
Hi Jeremy. I tested the tls option and I got the followinf error: Language string failed to load: tls Message could not be sent. Mailer Error: Language string failed to load: tls Then, if I try right after, it works! I'll give it a try to Pear. Thanks! –  Javier Jun 2 '12 at 10:04
    
okay great. You updated your answer to indicate you tried swiftmail. You should post that as an answer and then accept it (it's okay to answer your own question ... in fact, it's encouraged here) –  Jeremy W Jun 2 '12 at 14:44

I am not sure if the problem was the server or PHPMailer, but I tried Swiftmail and it worked fine. I usually like to know WHY something is not working but I can't find the problem and the technical service is as lost as I am. So I'm just going to stick to Swiftmail from now on for my projects.

Thanks for the help!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.