在 error_log 或頁(yè)面上沒(méi)有收到任何錯(cuò)誤。錯(cuò)誤日志肯定可以正常工作,就像我更改 require 'PHPMailer.php';為require 'PHPFailer.php';我得到的那樣PHP Fatal error: require(): Faileddisplay_errors 設(shè)置為 trueerror_reporting 設(shè)置為E_ALL & ~E_NOTICEPHPMailer 6.1.7 - PHP 7.2PHPMailer.php 和 Exception.php 都位于根目錄中。當(dāng)我剛剛發(fā)送到 /php/form_error.php 時(shí),已注釋掉重定向。任何想法將不勝感激,謝謝。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貢獻(xiàn)1719條經(jīng)驗(yàn) 獲得超6個(gè)贊
根據(jù)我的評(píng)論,當(dāng)出現(xiàn)問(wèn)題時(shí)你沒(méi)有做任何事情,所以沒(méi)有什么可看的。
要查看實(shí)際出了什么問(wèn)題,請(qǐng)?jiān)诔霈F(xiàn)問(wèn)題時(shí)輸出一些有用的信息,例如:
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);
}
沒(méi)有必要這樣做——PHPMailer 已經(jīng)設(shè)置為拋出異常,所以這應(yīng)該是:
$mail->send();
- 1 回答
- 0 關(guān)注
- 111 瀏覽
添加回答
舉報(bào)
0/150
提交
取消