我在服务器上安装了Pear,然后安装了Mail和SMTP组件。然后,我将php.ini文件更新为"include_path=".C:''wamp''bin''php''php5.4.3''pear",因为这就是Mail.php所在的位置。出于某种原因,当我通过web浏览器运行此测试脚本时,我会出现以下错误。
Warning: require_once(Mail.php): failed to open stream: No such file or directory in C:'wamp'www'email.php on line 3
和:
Fatal error: require_once(): Failed opening required 'Mail.php' (include_path='.;C:'php'pear') in C:'wamp'www'email.php on line 3
我是PHP的新手,在上周之前,我甚至从未听说过pear,因为我通常会设置交换服务器。如有任何帮助,我们将不胜感激。下面是测试脚本。
<?php
require_once "Mail.php";
$from = "Ty Jacobs <FROM_EMAIL>";
$to = "Ty Jacobs <TO_EMAIL>";
$subject = "Hi!";
$body = "Hi,'n'nHow are you?";
$host = "ssl://smtp.bizmail.yahoo.com";
$port = "465";
$username = "MYUSERNAME";
$password = "MYPASSWORD";
$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>");
}
?>
PHP.INI文件:
; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "'path1;'path2"
;include_path = ".;c:'php'includes"
include_path=".;C:'wamp'bin'php'php5.4.3'pear"
(include_path='.;C:'php'pear')
根据这一点,你的pear文件夹在php.ini中没有正确设置。你重新启动服务器了吗?
顺便说一句,您忘记了include路径字符串中的分号。应该是:
.;C:'wamp'bin'php'php5.4.3'pear
更改后是否重新启动WAMP web服务器?修改php.ini
后忽略重新启动服务器通常是您遇到此类问题的原因,因为在重新启动web服务器之前,配置更改不会被读入。