PHPMailer 表单没有错误或发送

在 error_log 或页面上没有收到任何错误。错误日志肯定可以正常工作,就像我更改 require 'PHPMailer.php';require 'PHPFailer.php';我得到的那样PHP Fatal error:  require(): Failed

display_errors 设置为 true

error_reporting 设置为E_ALL & ~E_NOTICE

PHPMailer 6.1.7 - PHP 7.2

PHPMailer.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';

    


泛舟湖上清波郎朗
浏览 63回答 1
1回答

慕侠2389804

根据我的评论,当出现问题时你没有做任何事情,所以没有什么可看的。要查看实际出了什么问题,请在出现问题时输出一些有用的信息,例如:catch (\Exception $e){&nbsp; &nbsp; $responseArray = ['type' => 'danger', 'message' => $e->getMessage()];&nbsp; &nbsp; var_dump($responseArray, $mail->ErrorInfo);}一件小事:&nbsp; &nbsp; if(!$mail->send()) {&nbsp; &nbsp; &nbsp; &nbsp; throw new \Exception('I could not send the email.' . $mail->ErrorInfo);&nbsp; &nbsp; }没有必要这样做——PHPMailer 已经设置为抛出异常,所以这应该是:$mail->send();
打开App,查看更多内容
随时随地看视频慕课网APP