PHP Pear 邮件返回致命错误:打开失败所需的“邮件.php”

2022-08-30 21:56:37

如何包含邮件.php使用PHP Pear Mail。我在测试文件中使用以下代码.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

有人能告诉我问题出在哪里吗?


答案 1

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

Linux:

梨安装邮件

窗户:

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

如果该过程已完成。

然后,请在脚本中包含您的Mail.php(可能在您实例化对象之前。这可能应该把你的警告踢开。Mail

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

set_include_path(“/path/to/pear”);包括“邮件.php”;

还要确保为 PHP 提供读取。there is enough permissionMail.php


答案 2

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

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


推荐