使用PHP进行“Cloudways”托管的绝对路径错误

问题描述 投票:0回答:2

我使用PHPmailer在PHP中发送电子邮件。它在localhost上运行正常,但它在cloudways托管服务器中给出了一个绝对路径错误。

我的目录结构。

-家

  • 的public_html PHPMailer的 sendmail.php

我需要phpmailer的代码是。

require_once dirname(__FILE__).'/PHPMailer-master/src/phpmailer.php

我还尝试了另一种方法 -

require_once '/home/xxxxxxx/public_html/phpmailer/PHPMailer-master/src/phpmailer.php

确切的错误是 -

Warning: require_once(/home/152903.cloudwaysapps.com/xxxxxxx/public_html/phpmailer/PHPMailer-master/src/phpMailer.php): failed to open stream: No such file or directory in /home/152903.cloudwaysapps.com/kjmwdjvxpz/public_html/check2.php on line 5

Fatal error: require_once(): Failed opening required '/home/152903.cloudwaysapps.com/kjmwdjvxpz/public_html/phpmailer/PHPMailer-master/src/phpMailer.php' (include_path='.:/usr/share/php') in /home/152903.cloudwaysapps.com/kjmwdjvxpz/public_html/check2.php on line 5

但它不起作用。有人能解决这个问题吗?

php phpmailer
2个回答
0
投票

在服务器上,目录结构是需要EXACT路径的。例如,如果你去你的服务器并打开yoursite.tld / Phpmailer并且实际目录是PHPMailer,那么你会收到404错误,因为大小写很重要。请求文件时,您需要使用它。你可以做的另一件事是:

require_once"./PHPMailer-master/src/phpmailer.php";

要么

require_once dirname(__FILE__)."PHPMailer-master/src/phpmailer.php

0
投票

你提到你有一个名为Phpmailer的文件夹但是在require语句中我注意到你使用的是phpmailer。请保持案件相似,否则不起作用。

根据文件夹名称将Phpmailer更改为phpmailer,反之亦然。它以这种方式在Windows上运行,但不适用于Linux系统,因为名称在那里区分大小写。

更新:

如上所述并非如此,请尝试以下其中一项要求声明 -

require_once dirname(__FILE__)."/phpmailer/PHPMailer-master/src/phpmailer.php"

或试试这个 -

require_once realpath(dirname(__FILE__))."/phpmailer/PHPMailer-master/src/phpmailer.php"

我注意到你要在public_html文件夹中的一个文件中要求这个类。所以你必须告诉代码开始从phpmailer文件夹中搜索文件,而不是直接搜索PHPMailer-master。因为PHPMailer-master存在于phpmailer文件夹中而不是直接存在于public_html文件夹中。

© www.soinside.com 2019 - 2024. All rights reserved.