【问题标题】:PHP Pear Mail Returns Fatal Error: Failed opening required 'Mail.php'PHP Pear Mail 返回致命错误:无法打开所需的“Mail.php”
【发布时间】:2011-09-18 13:35:39
【问题描述】:

如何包含 mail.php 以使用 PHP Pear Mail。我在 test.php 文件中使用以下代码:

    require_once "Mail.php";

    $from = "<test@gmail.com>";
    $to = "<testing@gmail.com>";
    $subject = "Hi!";
    $body = "Hi,\n\nHow are you?";

    $host = "ssl://smtp.gmail.com";
    $port = "465";
    $username = "<testtest@gmail.com>";
    $password = "testtest";

    $headers = array ('From' => $from,
      'To' => $to,
      'Subject' => $subject);
    $smtp = Mail::factory('smtp',
      array ('host' => $host,
        'port' => $port,
        'auth' => true,
        'username' => $username,
        'password' => $password));

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

    if (PEAR::isError($mail)) {
      echo("<p>" . $mail->getMessage() . "</p>");
    } else {
      echo("<p>Message successfully sent!</p>");
    }

通过此代码遇到以下错误:

  Warning: require_once(Mail.php) [function.require-once]: failed to open stream: No such file or directory in D:\Hosting\6525150\html\test.php on line 3

  Fatal error: require_once() [function.require]: Failed opening required 'Mail.php' (include_path='.;C:\php5\pear') in D:\Hosting\6525150\html\test.php on line 3

谁能告诉我是什么问题?

【问题讨论】:

    标签: php email pear


    【解决方案1】:

    我将这些步骤从网上拼凑起来,它可以工作:

    如何安装 PEAR: 1. Download go-pear.phar at http://pear.php.net/go-pear.phar & save to php directory (eg C:\Program Files\PHP\) 2. Open a command window as administrator, move to your php directory, CMD: php go-pear.phar 3. Accept the default value for everything it asks about; system wide, path options, updating your php.ini etc 4. In php directory double-click PEAR_ENV.reg to update your registry 然后你需要安装 PEAR MAIL: 5. CMD: php go-pear.phar 6. CMD: pear install --alldeps mail 7. CMD: pear channel-update pear.php.net 确保在你的电子邮件脚本中有这个:require_once "Mail.php";

    【讨论】:

      【解决方案2】:

      您的错误信息是不言自明的。确保您的机器上安装了 PEAR::Mail,如果没有,请安装它。

      Linux:

      pear 安装邮件

      窗户:

      http://www.geeksengine.com/article/install-pear-on-windows.html

      如果过程完成。

      然后请在您的脚本中包含您的 Mail.php(可能在您实例化 Mail 对象之前。这可能会消除您的警告。

      包括“/path/to/pear/Mail.php”;

      set_include_path("/path/to/pear"); 包括“Mail.php”;

      还要确保there is enough permission 提供给Mail.php 供PHP 读取。

      【讨论】:

      • 还不够include "Mail.php"; ?
      • @FranciscoCorrales - 是的,只要您在 PEAR 目录中安装了 Mail 包即可。
      【解决方案3】:

      检查系统中是否安装了pear。如果是,则在 php.ini include_path 指令中指定 Pear 安装目录的路径

      您需要安装 PEAR 和 PEAR MAIL 软件包才能使其正常工作

      【讨论】:

      • pear 安装在我的服务器上。并且包含路径是“;C:\php5\pear”
      • 你也需要安装Mail包
      • 同时使用 phpinfo() 检查 php include_path;
      • 我有同样的问题,我有 PEAR 但没有 Mail 包,搜索了一下 Mail 的安装非常简单:pear install Mail
      猜你喜欢
      • 2014-03-05
      • 2016-02-07
      • 2018-02-22
      • 2011-07-18
      • 1970-01-01
      • 2021-03-19
      • 2013-07-23
      • 2011-08-16
      • 2019-08-10
      相关资源
      最近更新 更多