我已经能够通过gmail从PHP发送电子邮件很长一段时间了,不知道发生了什么变化,但现在我无法做到。我创建了一个测试页面,并有以下代码列表,我仍然收到错误。有没有人看到任何错误?
错误: 无法设置发件人:@ [SMTP:从服务器收到无效的响应代码(代码:555,响应:5.5.2语法错误.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";
答案 0 :(得分:0)
经过漫长的过程后,我们终于发现我们在pear(http://pear.php.net/package/Mail/)中使用的Mail类已经过时,升级到新版本之后我们又可以通过gmail发送电子邮件了。