需要一些PHPMailer代码方面的帮助。发送表单时出现的日志错误如下所示。我已经阅读了所有引用这个错误的帖子,但我的问题是不同的,因为我不允许在我的托管公司的共享服务器上使用Composer。我正在执行文件的手动安装。
以下是日志文件错误:
[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下面是1719-1721行的代码,但是这个文件是PHPMailer的OOB:
if (!$result) {
throw new Exception($this->lang('instantiate'), self::STOP_CRITICAL);
}下面是我的php文件代码:
<?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;
}
}
?>下面是表单代码,这样你就有了它:
<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>发布于 2018-12-19 07:34:59
您的代码一开始似乎缺少所需的类。
您的示例包括:
<?php
use PHPMailer\PHPMailer\PHPMailer;
require '../PHPMailer/src/PHPMailer.php';您需要添加:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '../PHPMailer/src/Exception.php';
require '../PHPMailer/src/PHPMailer.php';
require '../PHPMailer/src/SMTP.php';这应该可以解决你在帖子中提到的PHP错误。
发布于 2018-12-19 07:34:19
如果不使用自动加载,则必须要求并使用代码中使用的任何类。
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '../PHPMailer/src/PHPMailer.php';
require '../PHPMailer/src/Exception.php';关于您对这个问题的评论,您没有在代码中使用异常,但PHPMailer类在内部使用了它们。将控制器的exceptions参数保留为空并不会完全禁用PHPMailer异常。如果你仔细查看源代码,你会发现throw new Exception...在if ($this->exceptions) { }中包装的一些地方,以及它无论如何都会抛出它们的其他地方。
在添加了require/use语句之后得到的异常并不是一个新问题,它是当你得到"class not found“错误时最初试图抛出的异常。
https://stackoverflow.com/questions/53842186
复制相似问题