doujiao3998 2018-12-18 22:42
浏览 609

PHPMailer抛出错误寻找PHPMailer \ PHPMailer \ Exception哪个不在我的代码中?

Need some help with PHPMailer code. Error from log is below which appears on send of form. Have read all of the posts referencing this same error but my issue is different as I am not allowed to use Composer on my hosting company's shared server. I am following a manual install of the files.

Here's the log file error:

[18-Dec-2018 22:30:51 UTC] PHP Fatal error:  Uncaught Error: Class 'PHPMailer\PHPMailer\Exception' not found in /home1/example/public_html/PHPMailer/src/PHPMailer.php:1720
Stack trace:
#0 /home1/example/public_html/PHPMailer/src/PHPMailer.php(1518): PHPMailer\PHPMailer\PHPMailer->mailSend('Date: Tue, 18 D...', '<html>".$feedba...')
#1 /home1/example/public_html/PHPMailer/src/PHPMailer.php(1352): PHPMailer\PHPMailer\PHPMailer->postSend()
#2 /home1/example/public_html/adoption/sendEmailTest.php(22): PHPMailer\PHPMailer\PHPMailer->send()
#3 {main}
  thrown in /home1/example/public_html/PHPMailer/src/PHPMailer.php on line 1720

Here's the code from lines 1719-1721, but this file is OOB for PHPMailer:

if (!$result) {
            throw new Exception($this->lang('instantiate'), self::STOP_CRITICAL);

Here's my php file code:


use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;

require '../PHPMailer/src/Exception.php';
require '../PHPMailer/src/PHPMailer.php';
require '../PHPMailer/src/SMTP.php';

    $email = $_POST['email'];
    $name = $_POST['name'];
    $feedback = $_POST['feedback'];

    $mail = new PHPMailer();

    $mail->setFrom('', 'Org Name');
    $mail->addReplyTo($email, $name);
    $mail->addAddress('', 'Org Name');


    $mail->Subject = 'Application Submission';  
    $mail->Body = '<html>".$feedback."</html>';

    if (!$mail->send())
        echo $mail->ErrorInfo;


Here's the form code so you have it:

    <form action="sendEmailTest.php" method="post" name="adoption">

        <table width="700" border="0" cellspacing="3" cellpadding="3">
                <td colspan="2" bgcolor="#FFFFCC"><h2><strong>Form Test</strong></h2></td>
                <td width="183"><label>Name: </label></td>
                <td width="496"><input name="name" type="text" required="required" id="name" value="" size="75" /></td>
                <td><label>Email Address: </label></td>
                <td><input type="text" name="email" id="email" value="" size="75" /></td>
                <td><textarea name="feedback" id="feedback" cols="45" rows="5"></textarea></td>
                <td><input type="submit" value="Submit Form" name="submit"/></td>
  • 写回答

2条回答 默认 最新

  • drvlf9739 2018-12-18 23:34

    Your code appears to be missing the required classes at the start.

    Your example includes:

    use PHPMailer\PHPMailer\PHPMailer;
    require '../PHPMailer/src/PHPMailer.php';

    You need to add:

    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;
    require '../PHPMailer/src/Exception.php';
    require '../PHPMailer/src/PHPMailer.php';
    require '../PHPMailer/src/SMTP.php';

    This should solve the PHP errors you mentioned in your post.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 Arduino,利用modbus的RS485协议,进行对外置的温湿度传感器进行数据读取
  • ¥15 vhdl+MODELSIM
  • ¥20 simulink中怎么使用solve函数?
  • ¥30 dspbuilder中使用signalcompiler时报错Error during compilation: Fitter failed,求解决办法
  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么