本文介绍了如何使用PEAR邮件发送html邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用PEAR邮件系统发送经过身份验证的邮件。我需要发送具有alink的HTML邮件。在我开始使用PEAR邮件之前,它工作正常。现在我无法发送HTML邮件。邮件正文如下:
$ body =<<< EOD
Hiya $ username
您可能对example.com上的当前haves和want感兴趣
最新的Haves
< a href =http://www.exmaple.com/product/have/64/Titan+Fast+Track+SunGlass> Titan Fast Track SunGlass< / a>
EOD;
一个标签出现在mail.Any中如何解决这个问题。
解决方案
如果您遵循这个例子,没有理由不应该工作:
< ;?
include('Mail.php');
include('Mail / mime.php');
//构造电子邮件
$ sender =Leigh< leigh@no_spam.net>; //您的姓名和电子邮件地址
$ recipient =Leigh< leigh@no_spam.net>; //收件人姓名和电子邮件地址
$ subject =测试电子邮件; //电子邮件的主题
$ text ='这是一条短信。 //电子邮件的文本版本
$ html ='< html>< body>< p>这是一个html消息< / p>< / body>< / html> //电子邮件的HTML版本
$ crlf =\\\
;
$ headers = array(
'From'=> $ sender,
'Return-Path'=> $ sender,
'Subject'=> $ subject
);
//创建Mime消息
$ mime = new Mail_mime($ crlf);
//设置邮件的正文
$ mime-> setTXTBody($ text);
$ mime-> setHTMLBody($ html);
$ body = $ mime-> get();
$ headers = $ mime-> headers($ headers);
//发送电子邮件
$ mail =&邮件::工厂(邮件);
$ mail-> send($ recipient,$ headers,$ body);
?>
注意
为了使上述示例工作需要Pear Mail Mime Package以及Pear Mail一个。您可以在这里获取包裹。
I am using PEAR mail system to send authenticated mails.I need to send HTML mails that has alinks.It was working fine before i started using PEAR mail.Now i am not able to send HTML mails.
mail body looks like this:
$body = <<<EOD
Hiya $username
You might be interested in the current 'haves' and 'wants' on example.com
Latest Haves
<a href="http://www.exmaple.com/product/have/64/Titan+Fast+Track+SunGlass">Titan Fast Track SunGlass</a>
EOD;
a tag appears as it is in the mail.Any idea how to solve this??Pls help..
解决方案
If you follow this example there's no reason it shouldn't work:
<?
include('Mail.php');
include('Mail/mime.php');
// Constructing the email
$sender = "Leigh <leigh@no_spam.net>"; // Your name and email address
$recipient = "Leigh <leigh@no_spam.net>"; // The Recipients name and email address
$subject = "Test Email"; // Subject for the email
$text = 'This is a text message.'; // Text version of the email
$html = '<html><body><p>This is a html message</p></body></html>'; // HTML version of the email
$crlf = "\n";
$headers = array(
'From' => $sender,
'Return-Path' => $sender,
'Subject' => $subject
);
// Creating the Mime message
$mime = new Mail_mime($crlf);
// Setting the body of the email
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$body = $mime->get();
$headers = $mime->headers($headers);
// Sending the email
$mail =& Mail::factory('mail');
$mail->send($recipient, $headers, $body);
?>
NOTEIn order for the above example to work one needs the Pear Mail Mime Package in addition the Pear Mail one. You can get the package here https://pear.php.net/package/Mail_Mime/download.
这篇关于如何使用PEAR邮件发送html邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!