Bootstrap联系表格在表格提交上发送电子邮件

时间:2016-10-26 04:28:35

标签: php twitter-bootstrap

我在bootstrap中创建了一个表单,我使用php来检索用户填写的所有信息作为电子邮件。表格工作正常,但我得到的确认消息是在新页面上,而不是表格上方或下方的同一页面。

Bootstrap Code

<form id="main-contact-form" name="contact-form" method="post" action="sendmail.php" class="form-horizontal">
                            <div class="form-group">
                            <span class="col-sm-1"><i class="fa fa-user fa-2x"></i></span> 
                            <div class="col-sm-11">
                                <input type="text" name="name" class="form-control" required placeholder="Name">
                            </div>
                            </div> 
                            <div class="form-group">
                            <span class="col-sm-1 text-center"><i class="fa fa-envelope fa-2x"></i></span>
                            <div class="col-sm-11">
                                <input type="email" name="email" class="form-control" required placeholder="Email Id">
                            </div>
                            </div>
                            <div class="form-group">
                            <span class="col-sm-1 text-center"><i class="fa fa-phone-square fa-2x"> &nbsp;</i></span>
                            <div class="col-sm-11">
                                <input id="phone" name="phone" type="text" placeholder="Phone" class="form-control">
                            </div>
                        </div>
                            <div class="form-group">
                            <span class="col-sm-1 text-center"><i class="fa fa-pencil-square-o fa-2x"></i></span>
                            <div class="col-sm-11">
                                <textarea name="message" id="message" required class="form-control" rows="8" placeholder="Enter your massage for us here. We will get back to you within 24 Hours."></textarea>
                            </div>  
                            </div>                      
                            <div class="form-group">

                                <input type="submit" name="submit" class="input-btn" value="Send Message">
                            </div>
                        </form>

PHP代码

<?php

/* These are the variable that tell the subject of the email and where the email will be sent.*/

$emailSubject = 'New query ';
$mailto = 'xxx@xxx.com';

/* These will gather what the user has typed into the fieled. */

$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];


/* This takes the information and lines it up the way you want it to be sent in the email. */

$body = <<<EOD
<br><hr><br>
Name: $name <br> <br>
Email Address: $email <br> <br>
Phone Number: $phone <br> <br>
Message: $message<br>

EOD;

$headers = "From:XXX<xxx@xxx.com>\r\n"; // This takes the email and displays it as who this email is from.
$headers .= "Content-type: text/html\r\n"; // This tells the server to turn the coding into the text.
//$success = mail($mailto, $emailSubject, $body, $headers); // This tells the server what to send.

?>

提前致谢

0 个答案:

没有答案