gpt4 book ai didi

php - pear fatal error : Class 'Mail' not found . wamp

转载 作者:行者123 更新时间:2023-12-04 18:06:56 27 4
gpt4 key购买 nike

我在使用 pear 和 wamp 的发送邮件功能时遇到了一些问题。我完成了此链接中的步骤:( http://pear.php.net/manual/en/installation.checking.php ) 以检查我的 pear 是否安装正确,看来我安装正确。

<?php
require_once 'System.php';
var_dump(class_exists('System', false));
?>

上面的代码返回 bool(true)。所以我假设我的路径设置正确。但是对于下面的代码,我收到了一个错误。

<?php    
include 'Mail.php';
include 'Mail/mime.php' ;

$text = 'Text version of email';
$html = '<html><body>HTML version of email</body></html>';
$file = 'test.xls';
$crlf = "\n";
$hdrs = array(
'From' => 'myemail@gmail.com',
'Subject' => 'Test mime message'
);

$mime = new Mail_mime(array('eol' => $crlf));

$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($file, 'text/plain');

$body = $mime->get();
$hdrs = $mime->headers($hdrs);

$mail =& Mail::factory('mail');
$mail->send('myemail2@gmail.com', $hdrs, $body);
?>

此行有错误:$mail =& Mail::factory('mail'); fatal error :找不到“邮件”类

此外,我使用以下命令安装了 pear Mail:pear install Mail Mail_mime

如有任何帮助,我将不胜感激。

谢谢,

最佳答案

这个对我有用,试试这个方法

   function sendEmail($subject,$from,$to,$bodymsg,$cc=null)
{
require_once "Mail.php";
require_once "Mail/mime.php";

$crlf = "\n";


$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 = "myusername"; //<> give errors
$password = "mypass";

//$mime = new Mail_mime($crlf);
$mime = new Mail_mime(array('eol' => $crlf)); //based on pear doc
$mime->setHTMLBody($bodymsg);

//$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), '-f bounce@domain.com');


$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
echo $mail->getMessage();
} else {
echo "Message sent successfully!";
}
echo "\n
}

关于php - pear fatal error : Class 'Mail' not found . wamp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24167313/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com