php 如何使用php梨邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6409516/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to use php pear mail
提问by Deepa
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 = "<[email protected]>";
$to = "<[email protected]>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "<[email protected]>";
$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:\Hosting25150\html\test.php on line 3
Fatal error: require_once() [function.require]: Failed opening required 'Mail.php' (include_path='.;C:\php5\pear') in D:\Hosting25150\html\test.php on line 3
Can someone tell me what is the problem?
有人可以告诉我有什么问题吗?
采纳答案by Varun Mittal
Check if pear is installed in the system . If yes then specify path to Pear installation directory in php.ini include_path directive
检查系统中是否安装了梨。如果是,则在 php.ini include_path 指令中指定 Pear 安装目录的路径
You need to install PEAR and PEAR MAIL packages to get it working
您需要安装 PEAR 和 PEAR MAIL 软件包才能使其正常工作
回答by Rakesh Sankar
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:
Linux:
pear install Mail
梨安装邮件
Windows:
视窗:
http://www.geeksengine.com/article/install-pear-on-windows.html
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";
包括“/path/to/pear/Mail.php”;
or
或者
set_include_path("/path/to/pear"); include "Mail.php";
set_include_path("/path/to/pear"); 包括“Mail.php”;
Also make sure there is enough permission
given for Mail.php
for PHP to read.
还要确保there is enough permission
给Mail.php
PHP 阅读。
回答by Kevin
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. 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";