在 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 = '[email protected]'; $fromName = 'Info domain'; // an email address that will receive the email with the output of the form $sendToEmail = '[email protected]'; $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 關注
- 99 瀏覽
添加回答
舉報
0/150
提交
取消