Php 如何使用pear-mail-mime
如何在谷歌上使用pear邮件mime。我发现这可以让你在谷歌上使用pear邮件,而不是邮件mime:Php 如何使用pear-mail-mime,php,sendmail,Php,Sendmail,如何在谷歌上使用pear邮件mime。我发现这可以让你在谷歌上使用pear邮件,而不是邮件mime: require_once“Mail.php”; 需要一次“Mail/mime.php”; $from=“发件人”; $to=“接收方”; $subject=“欢迎使用SITENAME!”; $crlf=“\n”; $html=“这是html”; $headers=数组('From'=>$From, '至'=>$至, “主题”=>$Subject); $host=“smtp.gmail.com”;
require_once“Mail.php”;
需要一次“Mail/mime.php”;
$from=“发件人”;
$to=“接收方”;
$subject=“欢迎使用SITENAME!”;
$crlf=“\n”;
$html=“这是html”;
$headers=数组('From'=>$From,
'至'=>$至,
“主题”=>$Subject);
$host=“smtp.gmail.com”;
$port=465;
$username=“******@googlemail.com”;
$password=“*******”;
$mime=新邮件\u mime($crlf);
$mime->setHTMLBody($html);
$body=$mime->get();
$headers=$mime->headers($headers);
$smtp=Mail::工厂(“smtp”),数组(“主机”=>$host,
“端口”=>$port,
“auth”=>正确,
“用户名”=>$username,
“密码”=>$password));
$mail=$smtp->send($to、$headers、$body);
if(PEAR::isError($mail)){
echo$mail->getMessage();
}否则{
回显“消息已成功发送!”;
}
回音“\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!
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!
这是我使用=
通过Gmail发送PEAR邮件包和SMTP。享受吧!
@john:使用你发布的链接中的代码,像这样修改它--
到
请再试一次。无法对StealthyNinja的回答发表评论,因此我发布了自己的答案,对此表示抱歉 这个问题也有点老了,但我想这可能对其他人有用 要去除所有HTML标记和奇怪的字符,您必须准备好标题,以便电子邮件客户端能够正确读取电子邮件。在设置$headers数组后,请尝试以下操作:
$headers = $message->headers($headers);
在那之后它应该可以正常工作 看来您的电子邮件标题有问题。我根据pear邮件文档更新了你的代码(http://pear.php.net/manual/en/package.mail.mail-mime.example.php):
require_once“Mail.php”;
需要一次“Mail/mime.php”;
$from=“发件人”;
$to=“接收方”;
$subject=“欢迎使用SITENAME!”;
$crlf=“\n”;
$html=“这是html”;
$headers=数组('From'=>$From,
'至'=>$至,
“主题”=>$Subject);
//$host=“smtp.gmail.com”;
$host=”ssl://smtp.gmail.com"; // 请尝试使用ssl
$port=465;
$username=“******@googlemail.com”;
$password=“*******”;
//$mime=新邮件\u mime($crlf);
$mime=新邮件\u mime(数组('eol'=>$crlf))//基于pear-doc
$mime->setHTMLBody($html);
//$body=$mime->get();
$body=$mime->getMessageBody()//基于上述文件
$headers=$mime->headers($headers);
$smtp=Mail::工厂(“smtp”),数组(“主机”=>$host,
“端口”=>$port,
“auth”=>正确,
“用户名”=>$username,
“密码”=>$password));
$mail=$smtp->send($to、$headers、$body);
if(PEAR::isError($mail)){
echo$mail->getMessage();
}否则{
回显“消息已成功发送!”;
}
回音“\n”;
它对我有用,所以我希望它对你有用!
干杯
埃雷斯
除上述内容外,html电子邮件还需要html_字符集
$crlf = "\n";
$body = $mime->get(array('html_charset' => 'utf-8', 'text_charset' => 'utf-8', 'eol' => $crlf));
这将修复电子邮件中的缩写,如 我使用此代码删除了3D after=符号
$hdrs = array( 'From' => $from,
'To' => $to,
'Subject' => $subject );
$mime =& new Mail_mime();
$mime->setTXTBody($message);
if($htmlMessage==""){
$htmlMessage=$message;
}
$mime->setHTMLBody($htmlMessage);
if($attachmentIsFile){
if($attachment!=null)
$mime->addAttachment($attachment,'application/octet-stream',$attachmentName.extractExtension($attachment));
}else{
if($attachment!="")
$mime->addAttachment($attachment,'application/octet-stream',$attachmentName,false);
}
$body = $mime->get(array('text_encoding' => '8bit','html_encoding' => '8bit'));
$hdrs = $mime->headers($hdrs);
你能详细解释一下你的意思吗?@Pekka:我想@john的意思是他希望发送HTML电子邮件。对不起,PHP代码没有显示,该死的Markdown,现在就在那里。是的,我想发送一封HTML电子邮件^为什么要投否决票?我已经澄清了这个问题。可能是一个准确的猜测+1我仍然收到这样的电子邮件:亲爱的会员,为了验证您的帐户,请单击以下链接:
。享受=!
$body = $mime->get(array('text_charset' => 'utf-8'));
$headers = $message->headers($headers);
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";
$body = $mime->get(array('text_charset' => 'utf-8'));
$crlf = "\n";
$body = $mime->get(array('html_charset' => 'utf-8', 'text_charset' => 'utf-8', 'eol' => $crlf));
$hdrs = array( 'From' => $from,
'To' => $to,
'Subject' => $subject );
$mime =& new Mail_mime();
$mime->setTXTBody($message);
if($htmlMessage==""){
$htmlMessage=$message;
}
$mime->setHTMLBody($htmlMessage);
if($attachmentIsFile){
if($attachment!=null)
$mime->addAttachment($attachment,'application/octet-stream',$attachmentName.extractExtension($attachment));
}else{
if($attachment!="")
$mime->addAttachment($attachment,'application/octet-stream',$attachmentName,false);
}
$body = $mime->get(array('text_encoding' => '8bit','html_encoding' => '8bit'));
$hdrs = $mime->headers($hdrs);