doujiao3998 2018-12-18 22:42
浏览 608
已采纳

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:

<?php

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';

if(isset($_POST['submit'])){    
    $email = $_POST['email'];
    $name = $_POST['name'];
    $feedback = $_POST['feedback'];

    $mail = new PHPMailer();

    $mail->setFrom('myname@example.org', 'Org Name');
    $mail->addReplyTo($email, $name);
    $mail->addAddress('myname@example.org', 'Org Name');

    $mail->isHTML(true);

    $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">
            <tr>
                <td colspan="2" bgcolor="#FFFFCC"><h2><strong>Form Test</strong></h2></td>
            </tr>
            <tr>
                <td width="183"><label>Name: </label></td>
                <td width="496"><input name="name" type="text" required="required" id="name" value="" size="75" /></td>
            </tr>
            <tr>
                <td><label>Email Address: </label></td>
                <td><input type="text" name="email" id="email" value="" size="75" /></td>
            </tr>
            <tr>
                <td><label>Feedback</label></td>
                <td><textarea name="feedback" id="feedback" cols="45" rows="5"></textarea></td>
            </tr>
            <tr>
                <td><input type="submit" value="Submit Form" name="submit"/></td>
            </tr>
        </table>     
    </form>
  • 写回答

2条回答 默认 最新

  • drvlf9739 2018-12-18 23:34
    关注

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

    Your example includes:

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

    You need to add:

    <?php
    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿