0

I have been able to send email through gmail from PHP for a long time, and not sure what changed but now I can't. I created a testing page and have the following code list and I am still getting an error. Does anyone see anything that is wrong?

Error: Failed to set sender: @ [SMTP: Invalid response code received from server (code: 555, response: 5.5.2 Syntax error. fj1sm16678796oeb.5 - gsmtp)]

$from = "no-reply@mydomain.com <no-reply@mydomain.com>";
$to = "brad@mydomain.com <brad@mydomain.com>";
$subject = "Welcome to SITENAME!";
$crlf = "\n";
$html = "<h1> This is HTML </h1>";

$headers = array('From' => $from,
                 'To' => $to,
                 'Subject' => $subject);


$host = "ssl://smtp.gmail.com"; // try this one to use ssl
$port = 465;
$username = "no-reply@mydomain.com";
$password = "MyPasswordHere";

$mime =  new Mail_mime(array('eol' => $crlf)); //based on pear doc     
$mime->setHTMLBody($html);

$body = $mime->getMessageBody(); //based on pear doc above
$headers = $mime->headers($headers);

$smtp = Mail::factory("smtp",array("host" => $host,
                      "port" => $port,
                      "auth" => true,
                      "username" => $username,
                      "password" => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
    echo $mail->getMessage();
} else {
    echo "Message sent successfully!";
}
echo "\n";
Brad Wickwire
  • 1,093
  • 4
  • 16
  • 29
  • possible duplicate of [555 5.5.2 Syntax error. gmail's smtp](http://stackoverflow.com/questions/4321346/555-5-5-2-syntax-error-gmails-smtp) – Phil Apr 03 '14 at 03:36
  • ... which is itself a duplicate of this one - http://stackoverflow.com/questions/4421866/cakephp-smtp-emails-syntax-error – Phil Apr 03 '14 at 03:37
  • I have tried both the posts that you posted and I am still getting the same error. I have updated the code in the original post showing that I have made sure to include the name and email address in the from and to sections. Any other ideas? – Brad Wickwire Apr 23 '14 at 13:44

1 Answers1

0

After a long process we finally found that our Mail class we use from pear ( http://pear.php.net/package/Mail/ ) is outdated and after upgrading to the newer version we were able to send email through gmail again.

Brad Wickwire
  • 1,093
  • 4
  • 16
  • 29