PHP mailer error

ArK picture ArK · Feb 9, 2010 · Viewed 54.5k times · Source

I tried to use php mailer but errors as follows.

SMTP -> FROM SERVER:
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. Message could not be sent.

Mailer Error: SMTP Error: Could not authenticate. 

and my code

 <?php
        require("class.phpmailer.php")
        $mail = new PHPMailer();        
        $mail->IsSMTP();                                    
        $mail->Host = "smtp.gmail.com";  
        $mail->Port = 465;        
        $mail->SMTPAuth = true;     

        $mail->SMTPDebug = 2;  
        $mail->Username = "[email protected]";  
        $mail->Password = "xxxxxxxx";   
        $mail->From = "[email protected]";
        $mail->FromName = "Mailer";
        $mail->AddAddress("[email protected]", "mine");               
        $mail->WordWrap = 50;                                 
        $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";

        ?>

Answer

Ashley Schroder picture Ashley Schroder · Sep 19, 2011

I was getting this due to wrong port for SSL.

SSL = 465 TLS = 587

See: http://mail.google.com/support/bin/answer.py?hl=en&answer=13287