在会话中存储表单字段并将数据作为电子邮件发送

时间:2017-06-08 22:13:50

标签: php forms session

我之前创建了一个脚本,用于在会话数组中存储表单字段,并通过电子邮件发送它们。我现在试图将代码复制到一个较小的两页表单,它只是不起作用。我不确定我错过了什么。 会话开始和第一页的表单代码。

 <?php
 //let's start the session
 session_start();

//now, let's register our session variables
foreach($_POST as $k=>$v) {
$_SESSION['all_quote_details'][$k]=$v;
}
foreach ($_SESSION['all_quote_details'] as $k => $v){ $result .="".      $k.", ".$v."\n"; } 

 ?> 
 <form class="number-plate-form" action="/quote2/" method="post">
<div class="bit-2">
<div class="blue-fade">
<input id="reg"  placeholder="ENTER REG"  required=""  name="reg">     </div></div><div class="bit-2"> <input value="Quote" id="quote-button"   class="btn-block-m btn-lg btn-success pulse" type="submit"></div>
 </form>

第2页的代码

 <?php
//let's start the session
session_start();

//now, let's register our session variables
foreach($_POST as $k=>$v) {
$_SESSION['all_quote_details'][$k]=$v;
}

?> 
<form action="/post.php" method="post">
<div class="bit-2">

<h2 class="ac">Vehicle Details</h2>
<input id="make" class="niceField" type="text" placeholder="Enter your  vehicle make" name="make" required="">

       

              <h2 class="ac">Your Details</h2>
 <input id="Name" class="niceField" type="text" placeholder="Enter your name" name="name" required >
      <input id="Email" class="niceField" type="email" placeholder="Enter email address"  name="Email" required>
      <input id="Tel" class="niceField" type="tel" placeholder="Enter your contact number" name="Tel" required>

      <br class="cb" />

   <input class="submit" type="submit" value="Send" id="send"> 
   <?php foreach ($_SESSION['all_quote_details'] as $k => $v){ $result .="". $k.", ".$v."\n"; }


   ?>

电子邮件表格代码

 <?php
session_start();
foreach ($_SESSION['all_quote_details'] as $k => $v){ 
    $result .="". $k.",  ".$v."\n"; 
}

$to      = 'dan@dentalseoltd.co.uk';
$subject = 'TESTING ';
$message = "<td>Please See Quote   $result;</td>";


  $success =  mail($to, $subject, $message,$body, $headers); 

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}

?>

当电子邮件通过时,我只是从第一页获得第一个注册表单输入。有谁知道我哪里出错了?

0 个答案:

没有答案