如何使用php梨邮件

时间:2022-04-25 07:16:30

How to include mail.php for using PHP Pear Mail. I'm using the following code in test.php file:

如何包含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>");
    }

and the following error is encountered via this code:

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

  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

Can someone tell me what is the problem?

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

3 个解决方案

#1


12  

Check if pear is installed in the system . If yes then specify path to Pear installation directory in php.ini include_path directive

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

You need to install PEAR and PEAR MAIL packages to get it working

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

#2


20  

Your error message is self-explanatory. Make sure you have PEAR::Mail installed on your machine, if not then please install it.

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

Linux:

pear install Mail

梨安装邮件

Windows:

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

If the process is done.

如果过程完成。

Then please include your Mail.php in your script (probably before you instantiate Mail object. This should probably kick your warnings away.

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

include "/path/to/pear/Mail.php";

or

set_include_path("/path/to/pear"); include "Mail.php";

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

Also make sure there is enough permission given for Mail.php for PHP to read.

还要确保为Mail.php提供足够的权限以供PHP阅读。

#3


0  

I pieced together these steps from the web and it works:

我从网上拼凑了这些步骤,它起作用:

How to install 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 Then you need to install PEAR MAIL: 5. CMD: php go-pear.phar 6. CMD: pear install --alldeps mail 7. CMD: pear channel-update pear.php.net Make sure to have this in your email script: require_once "Mail.php";

如何安装PEAR:1。在http://pear.php.net/go-pear.phar下载go-pear.phar并保存到php目录(例如C:\ Program Files \ PHP \)2。打开命令作为管理员的窗口,移动到您的php目录,CMD:php go-pear.phar 3.接受它询问的所有内容的默认值;系统范围,路径选项,更新您的php.ini等4.在php目录中双击PEAR_ENV.reg更新您的注册表然后您需要安装PEAR MAIL:5。CMD:php go-pear.phar 6. CMD:pear安装--alldeps mail 7. CMD:pear channel-update pear.php.net确保在你的电子邮件脚本中有这个:require_once“Mail.php”;

#1


12  

Check if pear is installed in the system . If yes then specify path to Pear installation directory in php.ini include_path directive

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

You need to install PEAR and PEAR MAIL packages to get it working

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

#2


20  

Your error message is self-explanatory. Make sure you have PEAR::Mail installed on your machine, if not then please install it.

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

Linux:

pear install Mail

梨安装邮件

Windows:

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

If the process is done.

如果过程完成。

Then please include your Mail.php in your script (probably before you instantiate Mail object. This should probably kick your warnings away.

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

include "/path/to/pear/Mail.php";

or

set_include_path("/path/to/pear"); include "Mail.php";

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

Also make sure there is enough permission given for Mail.php for PHP to read.

还要确保为Mail.php提供足够的权限以供PHP阅读。

#3


0  

I pieced together these steps from the web and it works:

我从网上拼凑了这些步骤,它起作用:

How to install 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 Then you need to install PEAR MAIL: 5. CMD: php go-pear.phar 6. CMD: pear install --alldeps mail 7. CMD: pear channel-update pear.php.net Make sure to have this in your email script: require_once "Mail.php";

如何安装PEAR:1。在http://pear.php.net/go-pear.phar下载go-pear.phar并保存到php目录(例如C:\ Program Files \ PHP \)2。打开命令作为管理员的窗口,移动到您的php目录,CMD:php go-pear.phar 3.接受它询问的所有内容的默认值;系统范围,路径选项,更新您的php.ini等4.在php目录中双击PEAR_ENV.reg更新您的注册表然后您需要安装PEAR MAIL:5。CMD:php go-pear.phar 6. CMD:pear安装--alldeps mail 7. CMD:pear channel-update pear.php.net确保在你的电子邮件脚本中有这个:require_once“Mail.php”;