pear fatal错误:未找到类'Mail'.wamp

时间:2014-06-11 15:48:34

标签: php email pear fatal-error classnotfound

我在使用带有wamp的pear的发送邮件功能时遇到了一些麻烦。我完成了这个链接中的步骤:(http://pear.php.net/manual/en/installation.checking.php)检查我的梨是否安装正确,看起来我没错。

<?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: Class 'Mail' not found

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

我将不胜感激。

谢谢,

2 个答案:

答案 0 :(得分:1)

这个适用于我,试试这种方式

   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
}

答案 1 :(得分:0)

您需要指定已安装的PEAR Mail包的完整路径(而不是include 'Mail.php';),或者在php.ini include_path中包含该路径

同时使用您的邮件服务器的地址和端口更新php.ini ...因为您正在使用Mail的发送驱动程序&#34; mail&#34 ;,这是PHP的邮件()函数。虽然您可以将其指定为使用sendmail或SMTP服务器。