如何使用php梨邮件

Dee*_*epa 16 php email pear

如何包含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>");
    }
Run Code Online (Sandbox Code Playgroud)

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

  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
Run Code Online (Sandbox Code Playgroud)

谁能告诉我这是什么问题?

Rak*_*kar 21

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

Linux的:

梨安装邮件

视窗:

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

如果该过程完成.

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

包括"/path/to/pear/Mail.php";

要么

通过set_include_path( "/路径/到/梨"); 包括"Mail.php";

还要确保there is enough permissionMail.phpPHP阅读.


Var*_*tal 13

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

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

  • 你还需要安装邮件包 (2认同)
  • 我有同样的问题,我有PEAR但没有邮件包,在搜索了一下Mail的安装很简单:pear install Mail (2认同)