单击“提交”后显示模式并发送邮件

时间:2016-01-28 20:19:39

标签: php bootstrap-modal

我的模态没有显示。页面正在重新加载,然后我收到一封电子邮件。 您可以在下面找到我的代码。有人可以帮帮我...我认为问题是我的页面在点击提交按钮后重新加载。

在我使用的表单下面:

<form id="form" method="post" name="form" autocomplete="on">
                        <div class="row">
                            <div class="col-sm-6 nopadding-right">
                                <div class="input-group">
                                    <div class="input-group-addon"><span class="fa fa-user"></span></div>
                                    <input type="text" name="vname" placeholder="Name" class="form-control requiredField name" value="" />
                                </div>
                                <div class="input-group">
                                    <div class="input-group-addon"><span class="fa fa-phone"></span></div>
                                    <input type="text" name="vphone" placeholder="Phone" class="form-control requiredField phone" value="" />
                                </div>
                                <div class="input-group">
                                    <div class="input-group-addon"><span class="fa fa-at"></span></div>
                                    <input type="email" name="vmail" placeholder="Enter email" class="form-control requiredField email" value="" />
                                </div>
                            </div>
                                       <div class="col-sm-6">
                                <div class="input-group mail-block">
                                    <div class="input-group-addon"><span class="fa fa-pencil"></span></div><textarea class="form-control message" name="vtext" placeholder="Message" rows="4"></textarea><input class="btn btn-primary inverse-btn" id="send" name="confirm" type="submit" value="send">
                                </div>
                            </div>
                        </div>
                    </form>

模态:

            <div class="modal fade" id="Modal" tabindex="-1" role="dialog">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title" id="myModalLabel">Thank you</h4>
        </div>
        <div class="modal-body">
            <p>Thanks for getting in touch!</p>                     
        </div>    
    </div>
            </div></div>

我的PHP代码:

<?php if(isset($_POST["confirm"])){    if($_POST["vname"]==""||$_POST["vmail"]==""||$_POST["vphone"]==""||$_POST["vtext"]==""){
    echo "error";}else{
    $email=$_POST['vmail'];
    $email =filter_var($email, FILTER_SANITIZE_EMAIL);
    $email= filter_var($email, FILTER_VALIDATE_EMAIL);
    if (!$email){
        echo "error";
    }
    else{
        $subject = "mail " . $_POST['vname'];
        $message = $_POST['vtext'] . "\r\n" . ' phone ' . $_POST['vphone'] ."\r\n" . $_POST['vmail'];
        $headers = 'From:'. "xxx@email.com" . "\r\n"; // Sender's Email
        $headers .= 'Cc:'. "xxx@email.com" . "\r\n"; // Carbon copy to Sender
        $message = wordwrap($message, 70);
        mail("xxx.yy@xxx.com", $subject, $message, $headers);
        echo "<script type='text/javascript'>
        $(document).ready(function(){
        $('#Modal').modal('show');
        });
        </script>";
    }
}
}?>

1 个答案:

答案 0 :(得分:0)

补救措施是使用<cfif isBoolean(CGI.server_port_secure) AND CGI.server_port_secure> <cflocation url="http://www.example.com" addtoken="false" /> </cfif> 来代替表单提交。它还允许您进行更好的错误处理。