Github PHPMailer联系表单脚本未发送邮件

时间:2019-05-24 15:04:29

标签: php phpmailer

我从Github下载了一个示例phpmailer脚本,我遵循了所有必要的步骤,但是当单击“提交”按钮时,页面会刷新,并且没有表单数据发送到邮件,并且我也没有收到错误消息。

PHP表单脚本

<?php
$display_message="";
if (isset($_POST["submit"])){
    require "phpmailer/PHPMailerAutoload.php";
    $mail = new PHPMailer;

    $mail->Host= "mail.web.techguarantor.com.ng";
    $mail->Port= 587;
    $mail->SMTPAuth= true;
    $mail->SMTPSecure= "tls";
    $mail->Username= "info@web.techguarantor.com.ng";
    $mail->Password= "12345";

    $mail->setFrom($_POST["email"],$_POST["yourname"]);
    $mail->addAddress("info@web.techguarantor.com.ng");
    $mail->addReplyto($_POST["email"],$_POST["yourname"]);

    $mail->isHTML(true);
    $mail->Subject="Form Submission: ". $_POST["subject"];
    $mail->body="Message". $_POST["message"];

    if(!$mail->send()){
        $display_message = "Message not sent try again later";
    } 
    else{
        $display_message = "Message sent succesfully";
    }

}

?>

HTML表单

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);  ?>">

                        <div class="row">
                        <div class="form-group col-sm-6 col-md-6 col-lg-6">
                            <input type="text" class="form-control" name="yourname" placeholder="Name*" maxlength="35">
                            <span class ="error"><?php echo $yourname_err; ?></span>
                        </div>
                        <div class="form-group col-sm-6 col-md-6 col-lg-6">
                            <input type="email" class="form-control" name="email" placeholder="Email*">
                            <span class ="error"><?php echo $email_err; ?></span>
                        </div>
                        </div>


                        <div class="form-group">
                            <input type="text" class="form-control" name="subject" placeholder="Subject*" maxlength="35">
                            <span class ="error"><?php echo $subject_err; ?></span>
                        </div>

                        <div class="form-group">
                            <textarea class="form-control" rows="5" name="message" placeholder="Your Message" maxlength="250"></textarea>
                            <span class ="error"><?php echo $message_err; ?></span>
                        </div>

                        <button type="submit" name="submit" class="btn btn-default btn-lg">Submit</button>
                        <?php $display_message; ?>
                </form>

急需帮助

0 个答案:

没有答案