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

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条)

报告相同问题?

悬赏问题

  • ¥30 vb net 使用 sendMessage 如何输入鼠标坐标
  • ¥200 求能开发抖音自动回复卡片的软件
  • ¥15 关于freesurfer使用freeview可视化的问题
  • ¥100 谁能在荣耀自带系统MagicOS版本下,隐藏手机桌面图标?
  • ¥15 求SC-LIWC词典!
  • ¥20 有关esp8266连接阿里云
  • ¥15 C# 调用Bartender打印机打印
  • ¥15 我这个代码哪里有问题 acm 平台上显示错误 90%,我自己运行好像没什么问题
  • ¥50 C#编程中使用printDocument类实现文字排版打印问题
  • ¥15 找会编程的帅哥美女 可以用MATLAB里面的simulink编程,用Keil5编也可以。