2013-07-09 58 views
0

您好,我有以下代码,我有一个问题:如何通过各种形式和一个处理程序将数据传输到电子邮件通过电子邮件发送到PHP?

brief.php如何发布/发送多个表单数据电子邮件

<!-- http://codepen.io/shaligramk/pen/sKCJI --> 
    <div id="pt-main" class="pt-perspective"> 
     <div class="pt-page pt-page-1"> 
      <form method="post" action="send_form_email.php" accept-charset="UTF-8"> 
       //data 
      </form> 
     </div> 
     <div class="pt-page pt-page-2"> 
      <form method="post" action="send_form_email.php" accept-charset="UTF-8"> 
       //data 
      </form> 
     </div> 
     <div class="pt-page pt-page-3"> 
      <form method="post" action="send_form_email.php" accept-charset="UTF-8"> 
       //data  
      </form> 
     </div> 


     <div class="pt-page pt-page-4"> 
      <form method="post" action="send_form_email.php" accept-charset="UTF-8"> 
       /data 
      </form> 
     </div> 
    </div> 

<b><i>send_form_email.php</i></b> 

<?php 

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

    // EDIT THE 2 LINES BELOW AS REQUIRED 

    $email_to = "[email protected]"; 

    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_site']) || 
     !isset($_POST['first_site_functions'])|| 
     !isset($_POST['name_surname']) || 
     !isset($_POST['domen_hosting_yes'])){ 
     died('We are sorry, but there appears to be a problem with the form you submitted.'); 
    } 

    // FIRST SLIDE 
    $first_site = $_POST['first_site']; // required 
    $first_site_functions= $_POST['first_site_functions']; // not required 
    $name_surname = $_POST['name_surname']; 

    // SECOND SLIDE 
    $domen_hosting_yes = $_POST['domen_hosting_yes']; 

    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 .="</body></html>"; 
    $email_message .="<h4>".clean_string($name_surname) . " хочет создать сайт!</h4>"; 

     $email_message .="<table style=' display:table; 
        margin-left:auto; 
        margin-right:auto; 
        border-collapse: collapse;'>"; 


       $email_message .="<tbody>"; 
         $email_message .="<tr style='border:1px solid #c6c9cc;padding:12px;'>"; 
           $email_message .= "<td style=' border:1px solid #c6c9cc; 
        padding:12px;'>".clean_string($first_site)."</td>"; 
           $email_message .= "<td style='style=' border:1px solid #c6c9cc; 
        padding:12px;''>".clean_string($first_site_functions)."</td>"; 
           $email_message .= "<td style='style=' border:1px solid #c6c9cc; 
        padding:12px;''>".clean_string($domen_hosting_yes)."</td>"; 
         $email_message .="</tr>"; 
       $email_message .="</tbody>"; 

     $email_message .= "</table>"; 
     $email_message .="</body></html>"; 
// $email_message .= "Comments: ".clean_string($comments)."\n"; 
// create email headers 
     $email_subject = " Пользователь ".clean_string($name_surname) ." хочет создать свой сайт"; 
     $headers = 'From: '.$email_from."\r\n". 
     $headers .= 'Reply-To: '.$email_from."\r\n" . 
     $headers = 'MIME-Version: 1.0' . "\r\n"; 
     $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
     $headers .= 'X-Mailer: PHP/' . phpversion(); 
     echo (int) mail($email_to, $email_subject, $email_message, $headers); 
    ?>`code` 
    <!-- include your own success html here --> 
    <?php header("Location:http://s-group.in.ua/"); ?> 

回答

0

,你可以在时间后一种形式。

你可以使用数组形式瓦尔的形式,所以我们的代码看起来应该是这样

<form method="post" action="send_form_email.php" accept-charset="UTF-8"> 
    <div id="pt-main" class="pt-perspective"> 
     <div class="pt-page pt-page-1"> 

       <input tyupe="text" name="yourSitesNames[]" /> 
       //data 

     </div> 
     <div class="pt-page pt-page-2"> 

       <input tyupe="text" name="yourSitesNames[]" />    
       //data 

     </div> 
     <div class="pt-page pt-page-3"> 

       //data 
      <input tyupe="text" name="yourSitesNames[]" /> 

     </div> 


     <div class="pt-page pt-page-4"> 

       //data 
      <input tyupe="text" name="yourSitesNames[]" /> 

     </div> 
    </div> 
</form> 

可以用PHP访问thhese瓦尔:

$_POST['yourSitesNames'][0]; 
$_POST['yourSitesNames'][1]; 
$_POST['yourSitesNames'][2]; 

等等

+0

'code'$('#send_data_button')。bind('click',function(){$。ajax({type:“POST”,url:“send_form_email.php”,data:$('input [type =“ text']')})};'/ code'我认为这是我的问题中的答案代码 – alfared