Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用PEAR邮件发送html邮件_Php_Email_Pear - Fatal编程技术网

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

Php 如何使用PEAR邮件发送html邮件,php,email,pear,Php,Email,Pear,我正在使用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.

我正在使用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;

$body=如果您遵循此示例,则没有理由认为它不起作用:

<?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 Mime包之外,还需要Pear Mail Mime包。你可以在这里拿到包裹

请注意,karim79发布的示例中有一个标题参数,可能会让您非常难过: “返回路径”-当我像示例一样包含此参数时,它阻止我添加发件人名称,只有发件人电子邮件地址起作用

特别是(当我添加调试参数以查看发生了什么情况时),在发件人名称周围添加了额外的尖括号,因此它试图将其发送到smtp服务器:

发件人:或
发件人:当我尝试使用引号时。
这导致smtp连接退出,错误为无效地址


此外,在使用mime_邮件类时,您需要在邮件头中指定“to:”参数,否则当您收到邮件时,它将被发送到未公开的地址。因此,将返回路径参数替换为To参数,它就会工作。

您的头是什么样子的?这是我的:

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

请看一下Mail_mime软件包。它允许您同时包含html和纯文本版本的电子邮件:SMTP服务器配置如何?您有相关链接吗?您好,我了解到,
$headers
中有
。我想知道
send()
方法中的收件人电子邮件
$recipient
$headers
变量中的收件人电子邮件
$recipient
有什么区别?是否有必要将
放入
$headers
中?@karim79-您能帮助我吗?您如何处理此错误?如果电子邮件不发送,或者SMTP服务器关闭,会发生什么情况?此代码不适用于这两种情况。(我提出这个问题是因为我正在寻找一个有错误处理的例子。)@John我希望你能帮我解决这个问题,谢谢你的作品非常出色,没有人需要去寻找额外的库而没有额外的库@你能帮我吗?