我正在实现一个代码,访问者可以给我们公司发电子邮件。
在my gmail。php中,第11行
require_once('PHPMailerAutoload.php') or exit();
它给出的错误是当我运行时它是
Warning: require_once(1) [function.require-once]: failed to open stream: No such file or directory in /home/maxsell/public_html/php/gmail.php on line 11
Fatal error: require_once() [function.require]: Failed opening required '1' (include_path='/home/maxsell/php:.:/usr/lib/php:/usr/local/lib/php') in /home/maxsell/public_html/php/gmail.php on line 11
如果我点击[function.require-once]
它会加载
The requested URL /php/function.require-once was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
我在我们的另一个网站上做了这个,它在那里工作。我试着改变require_once
的文件路径,但它不起作用。gmail.php和phpmailerautolload .php在同一个文件夹下。
编辑:这里是一个目录的内容目录内容
问题出在or exit()
部分
使用
require_once("test.php") or exit();
我得到相同的错误,但是
require_once("test.php");
如果文件存在则工作,如果不存在则抛出正确错误。
通常的语法是
require_once "test.php";
和or exit()
部分无论如何都是多余的,因为如果找不到文件,require会退出脚本本身。
经过一些测试后,我怀疑这个奇怪错误的内部工作原理是require_once不是一个函数,而是一个命令结构,这意味着
require_once('PHPMailerAutoload.php') or exit();
在功能上与
相同require_once ('PHPMailerAutoload.php' or exit());
,因为or
-运算符优先。
使你的require失败,因为('PHPMailerAutoload.php' or exit())
解析为true
,有效地使php尝试require(true)
,必须失败
你可以使用这个,希望它会为你工作
require_once($_SERVER['DOCUMENT_ROOT'].'/phpmailerfoldername/PHPMailerAutoload.php');