2016-06-10 103 views
-5

我在引导程序中有一个联系表单,通过电子邮件发送很有用。 但是我想在引导模式中“谢谢你,并且会回复你”,并成功发送消息。在引导模式中说声谢谢

我的问题是,我怎么可以把代码显示消息“谢谢”在引导模式成功发送电子邮件后在那里说@mail($email_to, $email_subject, $email_message, $headers);

<form name="contactform" method="post" action="send_form_email.php"> 
        <div class="panel-body"> 
         <div class="form-group"> 
          <div class="input-group"> 
           <span class="input-group-addon"><i class="glyphicon glyphicon-user blue"></i></span> 
           <input type="text" name="first_name" placeholder="Name" class="form-control" autofocus="autofocus" required> 
          </div> 
         </div> 
         <div class="form-group"> 
          <div class="input-group"> 
           <span class="input-group-addon"><i class="glyphicon glyphicon-envelope blue"></i></span> 
           <input type="email" name="email" placeholder="Email" class="form-control" required> 
          </div> 
         </div> 
         <div class="form-group"> 
          <div class="input-group"> 
           <span class="input-group-addon"><i class="glyphicon glyphicon-phone blue"></i></span> 
           <input type="number" name="telephone" placeholder="Phone" class="form-control" required> 
          </div> 
         </div> 
         <div class="form-group"> 
          <div class="input-group"> 
           <span class="input-group-addon"><i class="glyphicon glyphicon-comment blue"></i></span> 
           <textarea name="comments" rows="3" class="form-control" type="text" required></textarea> 
          </div> 
         </div> 
         <div class=""> 
         <button type="submit" class="btn btn-info pull-right" >Email Form</a> 
         Send <span class="glyphicon glyphicon-send"></span></button> 
          <button type="reset" value="Reset" name="reset" class="btn">Reset <span class="glyphicon glyphicon-refresh"></span></button> 
         </div> 
        </div> 
        </form> 
       </div> 
      </div> 
     </div> 
    </div> 

<div class="modal fade" id="modal-container-784141" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
       <div class="modal-dialog"> 
        <div class="modal-content"> 
         <div class="modal-header"> 

          <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> 
           × 
          </button> 
          <h4 class="modal-title" id="myModalLabel"> 
           Modal title 
          </h4> 
         </div> 
         <div class="modal-body"> 
          ... 
         </div> 
         <grammarly> 
          <div class="_9b5ef6-textarea_btn _9b5ef6-not_focused"> 
           <div class="_9b5ef6-transform_wrap"> 
            <div class="_9b5ef6-status"> 
            </div> 
           </div> 
          </div> 
         </grammarly> 
         <div class="modal-footer"> 

          <button type="button" class="btn btn-default" data-dismiss="modal"> 
           Close 
          </button> 
          <button type="button" class="btn btn-primary"> 
           Save changes 
          </button> 
         </div> 
        </div> 

       </div> 

      </div> 

     </div> 

<?php 

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



    // EDIT THE 2 LINES BELOW AS REQUIRED 

    $email_to = "xxxt"; 

    $email_subject = "Your email subject line"; 





    function died($error) { 

     // your error code can go here 

     echo "We are very sorry, but there were error(s) found with the form you submitted. "; 

     echo "These errors appear below.<br /><br />"; 

     echo $error."<br /><br />"; 

     echo "Please go back and fix these errors.<br /><br />"; 

     die(); 

    } 



    // validation expected data exists 

    if(!isset($_POST['first_name']) || 

     !isset($_POST['email']) || 

     !isset($_POST['telephone']) || 

     !isset($_POST['comments'])) { 

     died('We are sorry, but there appears to be a problem with the form you submitted.');  

    } 



    $first_name = $_POST['first_name']; // required 

    $email_from = $_POST['email']; // required 

    $telephone = $_POST['telephone']; // not required 

    $comments = $_POST['comments']; // required 



    $error_message = ""; 

    $email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; 

    if(!preg_match($email_exp,$email_from)) { 

    $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; 

    } 

    $string_exp = "/^[A-Za-z .'-]+$/"; 

    if(!preg_match($string_exp,$first_name)) { 

    $error_message .= 'The First Name you entered does not appear to be valid.<br />'; 

    } 

    if(strlen($comments) < 2) { 

    $error_message .= 'The Comments you entered do not appear to be valid.<br />'; 

    } 

    if(strlen($error_message) > 0) { 

    died($error_message); 

    } 

    $email_message = "Form details below.\n\n"; 



    function clean_string($string) { 

     $bad = array("content-type","bcc:","to:","cc:","href"); 

     return str_replace($bad,"",$string); 

    } 



    $email_message .= "First Name: ".clean_string($first_name)."\n"; 

    $email_message .= "Email: ".clean_string($email_from)."\n"; 

    $email_message .= "Telephone: ".clean_string($telephone)."\n"; 

    $email_message .= "Comments: ".clean_string($comments)."\n"; 





// create email headers 

$headers = 'From: '.$email_from."\r\n". 

'Reply-To: '.$email_from."\r\n" . 

'X-Mailer: PHP/' . phpversion(); 

@mail($email_to, $email_subject, $email_message, $headers); 




?> 




<?php 

} 

?> 
+0

这是什么问题?给你代码?请向我们提供您使用*相关*代码描述的具体而简明的问题。 – Li357

+0

我的问题是,我怎么能让代码在引导模式中显示消息“谢谢”后成功发送消息,它说@mail($ email_to,$ email_subject,$ email_message,$ headers); – alidads

回答

0

消息我假设你要在你的php代码中显示你的模态对话框,所以这里是我所做的代码(基于你的php代码):

<?php 
 

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

 

 

 
    // EDIT THE 2 LINES BELOW AS REQUIRED 
 

 
    $email_to = "xxxt"; 
 

 
    $email_subject = "Your email subject line"; 
 

 

 

 

 

 
    function died($error) { 
 

 
     // your error code can go here 
 

 
     echo "We are very sorry, but there were error(s) found with the form you submitted. "; 
 

 
     echo "These errors appear below.<br /><br />"; 
 

 
     echo $error."<br /><br />"; 
 

 
     echo "Please go back and fix these errors.<br /><br />"; 
 

 
     die(); 
 

 
    } 
 

 

 

 
    // validation expected data exists 
 

 
    if(!isset($_POST['first_name']) || 
 

 
     !isset($_POST['email']) || 
 

 
     !isset($_POST['telephone']) || 
 

 
     !isset($_POST['comments'])) { 
 

 
     died('We are sorry, but there appears to be a problem with the form you submitted.');  
 

 
    } 
 

 

 

 
    $first_name = $_POST['first_name']; // required 
 

 
    $email_from = $_POST['email']; // required 
 

 
    $telephone = $_POST['telephone']; // not required 
 

 
    $comments = $_POST['comments']; // required 
 

 

 

 
    $error_message = ""; 
 

 
    $email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; 
 

 
    if(!preg_match($email_exp,$email_from)) { 
 

 
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; 
 

 
    } 
 

 
    $string_exp = "/^[A-Za-z .'-]+$/"; 
 

 
    if(!preg_match($string_exp,$first_name)) { 
 

 
    $error_message .= 'The First Name you entered does not appear to be valid.<br />'; 
 

 
    } 
 

 
    if(strlen($comments) < 2) { 
 

 
    $error_message .= 'The Comments you entered do not appear to be valid.<br />'; 
 

 
    } 
 

 
    if(strlen($error_message) > 0) { 
 

 
    died($error_message); 
 

 
    } 
 

 
    $email_message = "Form details below.\n\n"; 
 

 

 

 
    function clean_string($string) { 
 

 
     $bad = array("content-type","bcc:","to:","cc:","href"); 
 

 
     return str_replace($bad,"",$string); 
 

 
    } 
 
} else { 
 
\t ?> 
 

 
\t <!-- Modal Thank You --> 
 
<div id="input_barang" class="modal fade" role="dialog"> 
 
    <div class="modal-dialog modal-sm"> 
 

 
    <!-- Modal content--> 
 
    <div class="modal-content"> 
 
     <div class="modal-header"> 
 
     <button type="button" class="close" data-dismiss="modal">&times;</button> 
 
     <!--<h4 class="modal-title">Input Jenis Barang</h4>--> 
 
     </div> 
 
     <div class="modal-body"> 
 
     \t 
 
     \t Than You ! 
 

 
     </div> 
 
     <div class="modal-footer"> 
 
     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
 
     </div> 
 
    </div> 
 

 
    </div> 
 
</div> 
 

 
<?php } ?>

你没有与关闭您的第一个“如果”声明“}”,所以我说在位于上方的clean_string函数,第一个“如果”语句else语句。希望它有帮助,祝你好运!

+0

是的,我已经尝试过,今天早上,它根本不工作,只是保持相同的空白页面,但不显示模态。任何想法! – alidads