dongque6377 2015-01-10 16:01
浏览 37
已采纳

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

I am trying send an email through my contact form, here is my php code:

    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 
";

    $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.";
}

when I press send, it goes to the next page and it gives me "something not working" error. I am not quite sure what is going wrong here.

this is my contact form:

<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>

what is going wrong?

  • 写回答

1条回答 默认 最新

  • douli7841 2015-01-10 16:11
    关注

    Are you using a live test server for this or are you using the likes of an offline server such as Apache? If you are using an offline server the email will not send unless you have setup utilities to do so.

    This is not an answer, but due to a lack of 50 rep I cannot comment.

    EDIT

    Suggestion of an auto-redirect after the post has been sent, rather than a manual link.

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

    Something like this can work, by adding to your existing code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 哪个tomcat中startup一直一闪而过 找不出问题
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码