繁体   English   中英

如何使用PEAR邮件发送html邮件

[英]how to send html mails using PEAR mail

我正在使用PEAR邮件系统发送经过身份验证的邮件。我需要发送具有alink的HTML邮件。在我开始使用PEAR邮件之前它工作正常。现在我无法发送HTML邮件。

邮件正文如下:

$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;

一个标签出现在邮件中。任何想法如何解决这个问题?请帮忙..

如果您遵循此示例,则没有理由不应该这样做:

<?php
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>HTML message</p></body></html>';// HTML version of the email
$crlf = "\r\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);
?>

注意:为了使上面的例子工作,除了Pear Mail之外,还需要Pear Mail Mime Package。 你可以在这里获得包https://pear.php.net/package/Mail_Mime/download

你的标题是什么样的? 这是我的:

$headers = array(
    'To' => $recipients,
    'From' => $adminEmail,
    'Subject' => $subject,
    'MIME-Version' => 1,
    'Content-type' => 'text/html;charset=iso-8859-1'
);

请注意,karim79发布的示例有一个标题参数可能会让您感到非常悲伤:“返回路径” - 当我包含此参数时,例如它阻止我添加一个名称,只有发件人电子邮件地址有效。

具体来说(当我添加调试参数以查看发生的情况时)在名称周围添加了额外的尖括号,因此它尝试将其发送到smtp服务器:

来自:<来自名称<name@domain.com >>或
来自:<“来自名称”<name@domain.com >>当我尝试使用引号时。
这导致smtp连接退出并出现无效地址错误。

此外,在使用mime_mail类时,您需要在标题中指定“To:”参数,否则当您收到它时,它将显示为发送到未公开的地址。 因此,使用To param替换Return-Path参数,它将起作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM