如何包含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
有人可以告诉我这是什么问题吗?
答案 0 :(得分:21)
您的错误消息不言自明。确保你的机器上安装了PEAR :: Mail,如果没有,请安装它。
Linux的:
pear install Mail
视窗:
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 permission
提供Mail.php
以供PHP阅读。
答案 1 :(得分:13)
检查系统中是否安装了pear。如果是,则在php.ini include_path指令
中指定Pear安装目录的路径您需要安装PEAR和PEAR MAIL包才能使其正常工作
答案 2 :(得分:0)
我将这些步骤从网络拼凑起来并且有效:
如何安装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”;