0

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

简介.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 = "alfared3006@gmail.com";

    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/"); ?>
4

1 回答 1

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 中访问这些变量:

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

ETC...

于 2013-07-09T08:14:26.503 回答