Php 使用PEAR邮件发送测试邮件时出现错误消息
我已经安装了PEAR Mail和Mail_Mime的最新版本,我正在尝试发送一条测试消息,使用以下来自的测试电子邮件,即Php 使用PEAR邮件发送测试邮件时出现错误消息,php,email,pear,mime,Php,Email,Pear,Mime,我已经安装了PEAR Mail和Mail_Mime的最新版本,我正在尝试发送一条测试消息,使用以下来自的测试电子邮件,即 应该是您的include。不应该静态地调用它。您确定这是正确的文件吗?有一个版本带有“return Mail\u mimePart::encodeHeader”(“但这不是您要显示的内容。您是如何安装Mail和Mail\u mime的?您应该能够使用:include\u once”(“Mail/mime.php”)调用。pear install Mail和pear insta
应该是您的include。不应该静态地调用它。您确定这是正确的文件吗?有一个版本带有“return Mail\u mimePart::encodeHeader”(“但这不是您要显示的内容。您是如何安装Mail和Mail\u mime的?您应该能够使用:
include\u once”(“Mail/mime.php”)
调用。pear install Mail
和pear install Mail_mime
应该是您安装它们的方式。它们是使用cPanel安装的。@David使用include_once(“Mail/mime.php”);
修复了这个问题,因此如果您想将其添加为答案,我可以将其标记为正确。谢谢。
<?
include('/home/****/php/Mail.php');
include('/home/****/php/Mail/mime.php');
// Constructing the email
$sender = "**** <info@****.com>"; // Your name and email address
$recipient = "**** <****@gmail.com>"; // 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);
?>
function encodeHeader($name, $value, $charset, $encoding)
{
$mime_part = new Mail_mimePart;
return $mime_part->encodeHeader(
$name, $value, $charset, $encoding, $this->_build_params['eol']
);
}
include_once("Mail/mime.php");