你如何使用谷歌的梨邮件mime.我发现这可以让你使用谷歌邮件,但不是邮件mime:http://globalconstant.scnay.com/2009/11/06/sending-email-through-gmail-using-php/
require_once "Mail.PHP";
require_once "Mail/mime.PHP";
$from = "Sender <*******@googlemail.com>";
$to = "Receiver <*******@googlemail.com>";
$subject = "Welcome to SITENAME!";
$crlf = "\n";
$html = "<h1> This is HTML </h1>";
$headers = array('From' => $from,
'To' => $to,
'Subject' => $subject);
$host = "smtp.gmail.com";
$port = 465;
$username = "********@googlemail.com";
$password = "********";
$mime = new Mail_mime($crlf);
$mime->setHTMLBody($html);
$body = $mime->get();
$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";
我一直在
Failed to add recipient: @localhost
[SMTP: Invalid response code received
from server (code: 555, response:
5.5.2 Syntax error. f52sm5542930wes.35)]
编辑:
现在收到了电子邮件,但结果如下:
This is a message I sent from <a href=3D"http://www.PHP.net/">PHP</a> using=
the PEAR Mail package and SMTP through Gmail. Enjoy!
解决方法:
看起来您的电子邮件标题存在问题.我根据梨邮件文档更新了您的代码(http://pear.PHP.net/manual/en/package.mail.mail-mime.example.PHP):
require_once "Mail.PHP";
require_once "Mail/mime.PHP";
$from = "Sender <*******@googlemail.com>";
$to = "Receiver <*******@googlemail.com>";
$subject = "Welcome to SITENAME!";
$crlf = "\n";
$html = "<h1> This is HTML </h1>";
$headers = array('From' => $from,
'To' => $to,
'Subject' => $subject);
//$host = "smtp.gmail.com";
$host = "ssl://smtp.gmail.com"; // try this one to use ssl
$port = 465;
$username = "********@googlemail.com";
$password = "********";
//$mime = new Mail_mime($crlf);
$mime = new Mail_mime(array('eol' => $crlf)); //based on pear doc
$mime->setHTMLBody($html);
//$body = $mime->get();
$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";
它对我有用,所以我希望它对你有用!
干杯,
埃雷兹
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。