在 error_log 或页面上没有收到任何错误。错误日志肯定可以正常工作,就像我更改 require 'PHPMailer.php';为require 'PHPFailer.php';我得到的那样PHP Fatal error: require(): Faileddisplay_errors 设置为 trueerror_reporting 设置为E_ALL & ~E_NOTICEPHPMailer 6.1.7 - PHP 7.2PHPMailer.php 和 Exception.php 都位于根目录中。当我刚刚发送到 /php/form_error.php 时,已注释掉重定向。任何想法将不胜感激,谢谢。contact_post.php<?php /* THIS FILE USES PHPMAILER INSTEAD OF THE PHP MAIL() FUNCTION */ use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; require 'PHPMailer.php'; require 'Exception.php'; /* * CONFIGURE EVERYTHING HERE */ // an email address that will be in the From field of the email. $fromEmail = 'info@domain.co.uk'; $fromName = 'Info domain'; // an email address that will receive the email with the output of the form $sendToEmail = 'info@domain.co.uk'; $sendToName = 'Info domain'; // subject of the email $subject = 'New message from contact form'; // form field names and their translations. // array variable name => Text to appear in the email $fields = array('name' => 'Name', 'surname' => 'Surname', 'phone' => 'Phone', 'email' => 'Email', 'message' => 'Message'); // message that will be displayed when everything is OK :) $okMessage = 'Contact form successfully submitted. Thank you, I will get back to you soon!'; // If something goes wrong, we will display this message. $errorMessage = 'There was an error while submitting the form. Please try again later';
1 回答
慕侠2389804
TA贡献1719条经验 获得超6个赞
根据我的评论,当出现问题时你没有做任何事情,所以没有什么可看的。
要查看实际出了什么问题,请在出现问题时输出一些有用的信息,例如:
catch (\Exception $e)
{
$responseArray = ['type' => 'danger', 'message' => $e->getMessage()];
var_dump($responseArray, $mail->ErrorInfo);
}
一件小事:
if(!$mail->send()) {
throw new \Exception('I could not send the email.' . $mail->ErrorInfo);
}
没有必要这样做——PHPMailer 已经设置为抛出异常,所以这应该是:
$mail->send();
- 1 回答
- 0 关注
- 82 浏览
添加回答
举报
0/150
提交
取消