使用PHP

时间:2019-03-02 05:37:23

标签: php phpmailer

我正在使用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

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

2 个答案:

答案 0 :(得分:0)

您提到您有一个名为 Phpmailer 的文件夹,但是在require语句中,我注意到您正在使用 phpmailer 。请保持类似的情况,否则将无法正常工作。

根据文件夹名称将 Phpmailer 更改为 phpmailer ,反之亦然。它以这种方式在 windows 上运行,但在 linux 系统上不起作用,因为该名称区分大小写。

更新

由于上述情况并非如此,请尝试使用其中之一获取require语句-

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文件夹中。

答案 1 :(得分:0)

在服务器上,目录结构需要精确路径。例如,如果转到服务器并打开yoursite.tld / Phpmailer,而实际目录为PHPMailer,则由于大小写原因,将出现404错误。请求文件时,您需要使用该文件。您可以做的另一件事是:

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

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