dsag14654 2019-03-02 05:37
浏览 49

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

I am using PHPmailer for sending email in PHP. It is working fine on localhost but it gives me an error of absolute path in cloudways hosting server.

My directory structure.

-home

  • public_html

    • phpmailer

    • sendmail.php

My code for requiring phpmailer is.

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

I also tried another approach-

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

The exact error is-

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

But it does not work. Can someone sort out this problem?

  • 写回答

2条回答 默认 最新

  • douzai6337 2019-03-02 05:58
    关注

    You mentioned that you have a folder named Phpmailer but in the require statement I noticed you are using phpmailer. Please keep the cases similar otherwise it would not work.

    Change Phpmailer to phpmailer or vice versa depending on the folder name. It works on windows this way but would not work on a linux system as the names are case-sensitive there.

    Update:

    As above is not the case then please try one of these for require statements-

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

    Or try this-

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

    I noticed you are requiring this class in one of your file present in public_html folder. So you must tell the code to start searching for the file from phpmailer folder instead of searching directly for PHPMailer-master. Because PHPMailer-master exists in phpmailer folder not directly in public_html folder.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大