【问题标题】:pear fatal Error: Class 'Mail' not found .wamp梨致命错误:找不到类“邮件”.wamp
【发布时间】:2023-03-04 18:43:01
【问题描述】:

我在使用 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 =&amp; Mail::factory('mail');Fatal error: Class 'Mail' not found

另外,我用这个命令安装了 pear Mail:pear install Mail Mail_mime

我将不胜感激。

谢谢,

【问题讨论】:

  • 你检查include的返回值了吗?如果由于某种原因无法加载文件,它将返回布尔值 FALSE。
  • 嘿,马克,当我做 var_dump(include 'Mail.php');它返回 int(1)。 Mail/mime.php 也一样。
  • 它可能与 Zend Mail 类发生冲突吗?我问这个是因为如果我替换 include 'Mail.php';包括'C:/wamp/bin/php/php5.5.12/pear/Mail.php';然后运行脚本:- 我得到一个不同的错误:- 警告:mail():无法在“localhost”端口 25 连接到邮件服务器,验证 php.ini 中的“SMTP”和“smtp_port”设置或使用 ini_set( ) 在第 153 行的 C:\wamp\bin\p hp\php5.5.12\pear\Mail\mail.php 中。但是我的 smtp 设置又是正确的,我用简单的 php mail() 函数进行了测试。有什么想法吗?谢谢

标签: php email pear fatal-error classnotfound


【解决方案1】:

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

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

【讨论】:

  • 所以这是部分正确的。我想因为我使用的是 Zend,所以它从 Zend 而不是 pear 中获取 Mail.php。可能是 Zend 设置的一些优先问题。如果我确实包含 'C:/wamp/bin/php/php5.5.12/pear/Mail.php' ,效果很好。还有关于 smtp 设置。我忘了用我的 smtp 设置更新第二个 php.ini。更新了它,现在很好用。感谢版权
【解决方案2】:

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

   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
}

【讨论】:

  • 嗨,三一,谢谢。但我认为这里的问题不在于代码。我认为问题出在 include('Mail.php') 中。我认为它与 Zend/Mail.php 发生冲突。我坚持,我“认为”这就是正在发生的事情。包括 'C:/wamp/bin/php/php5.5.12/pear/Mail.php' 为我工作
  • 嘿,伙计,我也相信你的代码很好。但是你的 Mail.php 包含有问题。你不是这个问题,但是在文件包含之后,其他人可以解决这个问题.检查这里stackoverflow.com/questions/12989183/…
  • 嘿三一,我确实检查了那个帖子。我相信我已经通过使用 include 'Mail.php' 而不是 'Mail/mail.php' 做了正确的事情?除非您指出其他问题? .. 谢谢老兄,感谢您的帮助。
猜你喜欢
  • 2011-10-09
  • 2013-03-12
  • 2012-10-07
  • 1970-01-01
  • 1970-01-01
  • 2012-06-24
  • 1970-01-01
  • 2014-10-03
  • 1970-01-01
相关资源
最近更新 更多