试图通过联系表格发送电子邮件,但它不起作用

trying to send an email through contact form but it doesnt work

我正在尝试通过联系表发送电子邮件,这是我的 php 代码:

    if(isset($_POST['send'])) {

    $fn = $_POST['firstname'];
    $ln = $_POST['lastname'];
    $name = $fn . ' ' . $ln;
    $email = $_POST['email'];
    $message = $_POST['comment'];
    $subject = $_POST['subject'];

    $to = "iesteghlal@gmail.com";
    $header = "From: $email \r\n";

    $send_contact = mail($to, $subject, $message, $header);

    if($send_contact){
        echo "We've recived your contact information";
        echo "Your email has been sent. Stay in touch with us.";
        echo $name;
        echo $email;
        echo $message;
        echo $subject;
        echo $mailheader;
        echo $body;
        echo "</br><a href='index.html'> Go Back. </a>";
    }
    else {
        echo "something not working";
    }
}
else {
    echo "Something wrong.";
}

当我按下发送键时,它会转到下一页并给我 "something not working" 错误。我不太确定这里出了什么问题。

这是我的联系方式:

<form role="form" action="send.php" method="post" accept-charset="utf-8">
                    <div class="modal-body" style="padding: 5px; background-color:#D7D1D1;">
                          <div class="row">
                                <div class="col-lg-6 col-md-6 col-sm-6" style="padding-bottom: 10px;">
                                    <input class="form-control" id="firstname" name="firstname" placeholder="Firstname" required="" autofocus="" type="text">
                                </div>
                                <div class="col-lg-6 col-md-6 col-sm-6" style="padding-bottom: 10px;">
                                    <input class="form-control" id="lastname" name="lastname" placeholder="Lastname" required="" type="text">
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-lg-12 col-md-12 col-sm-12" style="padding-bottom: 10px;">
                                    <input class="form-control" id="email" name="email" placeholder="E-mail" required="" type="text">
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-lg-12 col-md-12 col-sm-12" style="padding-bottom: 10px;">
                                    <input class="form-control" id="subject" name="subject" placeholder="Subject" required="" type="text">
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-lg-12 col-md-12 col-sm-12">
                                    <textarea style="resize:vertical;" class="form-control" placeholder="Message..." rows="6" id="comment" name="comment" required=""></textarea>
                                </div>
                            </div>
                        </div>  
                        <div class="panel-footer">
                            <input class="btn btn-success" value="Send" type="submit" id="submit" name="send">
                                <!--<span class="glyphicon glyphicon-ok"></span>-->
                            <input class="btn btn-danger" value="Clear" type="reset">
                                <!--<span class="glyphicon glyphicon-remove"></span>-->
                            <button style="float: right;" type="button" class="btn btn-default btn-close" data-dismiss="modal">Close</button>
                        </div>
                    </form>

出了什么问题?

您是为此使用实时测试服务器还是使用类似 Apache 的离线服务器?如果您使用的是离线服务器,除非您有设置实用程序,否则电子邮件将不会发送。

这不是答案,但由于缺少 50 个代表,我无法发表评论。

编辑

建议 post 发送后自动重定向,而不是手动 link。

<script type="text/javascript">
    setTimeout('Redirect()', 5000)
    function Redirect() {
        location.href='contact.php'
    }
</script>

通过添加到您现有的代码,这样的东西可以工作。