douyong5825 2018-05-23 19:28
浏览 79

Phpmailer配置

I have installed phpmailer for cpanel using composer successfully.

The location of PHPMailer is at

root\vendor\phpmailer\phpmailer

now I want to use PHPmailer in one of my files at

root\public_html

What changes do I have to make to the following lines ?

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception; 
require 'vendor/autoload.php';

the code is not working with the above configuration.The rest of code is same as that given in the documentation (with correct values filled)

  • 写回答

1条回答 默认 最新

  • doudi1978 2018-05-23 20:23
    关注

    If your current working directory is root\public_html (I'm assuming you're on Windows since you're using \ in paths) and you want to load the composer autoloader from there when it's stored in root\vendor\autoload.php, you should load it from a relative path like this:

    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception; 
    require '../vendor/autoload.php';
    

    Note that the namespace aliases (the use lines) do not change.

    While this should work, a better solution is to add your app's root folder (in this example root\, wherever that is as an absolute path) to your php.ini's include_path setting, and that way the original vendor/autoload.php will work.

    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题