【发布时间】:2011-05-30 22:19:34
【问题描述】:
您如何在 google 中使用 pear mail 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";
我一直在努力
添加收件人失败:@localhost [SMTP:收到无效的响应代码 来自服务器(代码:555,响应: 5.5.2 语法错误。 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!
【问题讨论】:
-
你能详细说明你的意思吗?
-
@Pekka:我认为@john 的意思是他希望发送 HTML 电子邮件。
-
抱歉,PHP 代码没有显示出来,该死的 Markdown,它现在就在那里。是的,我想发送一封 HTML 电子邮件。 ^
-
为什么投反对票?我已经解决了这个问题。