dtnwm4807 2015-10-27 07:24
浏览 65

通过多个页面传递复选框值并使用php发送电子邮件

Hi I am creating a simple brochure request form to capture users brand and price information along with their email id. I created code for three pages (Page1.php is for brand selection, Page2.php is for price range and email address. I get user selected value for page1.php in the next page but I am not getting values in mail page (I need to collect those two page values here and submit to email). Please find the pages code below. Please help.

page1.php

<html>
<body  bgcolor="#fff" text="#000" >
<form method="post" action="page2.php">
<p>Which car you want to buy?<P>
<TABLE border="1" width="500">
<TR ><TD><input type="checkbox" value ="ferrari"  name="brand[]"><TD>Ferrari</td></TR>
<TR><TD><input type="checkbox" value ="mercedes"  name="brand[]"><TD>Mercedes</td></TR>
<TR><TD><input type="checkbox" value ="bugatti"  name="brand[]"><TD>Bugatti</td></TR>
</TABLE>
<input type="hidden" value="1" name="car_brand" >
<p>
<input type="submit" value="Continue" >
</form>
</body>
</html>

page2

<html>
<body  bgcolor="#fff" text="#000" >

<div id="firstpage-value" style="border:1px solid #000;">
<h4>Selected Brand</h4>
<?php
if(isset($_POST['car_brand']))
{   
    $count=count($_POST['brand']);
    for($i=0;$i<$count;$i++)
    {
        echo $_POST['brand'][$i]." ";
    }
}
?>
</div>

<form method="post" action="mail.php">
<p>Choose a Price Range<P>
<TABLE border="1" width="500">
<TR ><TD><input type="checkbox" value ="under20k"  name="price[]"><TD>Under $20K</td></TR>
<TR><TD><input type="checkbox" value ="35-85k"  name="price[]"><TD>$35K-$85K</td></TR>
<TR><TD><input type="checkbox" value ="over85k"  name="price[]"><TD>Over $85K</td></TR>
</TABLE>
<input type="text" name="email" value="email" />
<input type="hidden" value="1" name="car_price" >
<p>
<input type="submit" value="Submit" >

<input type="hidden" name="brand" value="<?php echo $_POST['brand']?>">
</form>
</body>
</html>

mail.php

<?php 
     
    

/* Subject and email variables */

$emailsSubject = 'Brochure Request';
$thanks = 'Thank you for requesting Brochure';
$webMaster  = 'mailsample@gmail.com';
$mailheader .= "Reply-To: ".$_POST["email"]."
";

//Get the input.
 $email = $_POST['email'];
$brand = $_POST['brand'];
$price = $_POST['price']; 


$body = '
<p>A user has been submitted "Request Brochure" form with the following info.</p>
<table width="600" border="1" >
      <tr>
      <th width="556" height="37" align="left"><h2>Which car you want to buy?</h2></th>
      <th width="268" style="border-bottom:1px solid #ccc; ">'.$brand.'</th>
    </tr>
    <tr>
      <th width="556" height="37" align="left"><h2>Choose price range</h2></th>
      <th width="268" style="border-bottom:1px solid #ccc; ">'.$price.'</th>
    </tr>
    
    <tr>
      <th width="556" height="37" align="left"><h2>Email Address</h2></th>
      <th width="268" style="border-bottom:1px solid #ccc; ">'.$emaild.'</th>
    </tr> 
    ';
    
    $headers = "From: $email
";
$headers .= "Content-type: text/html
";
$headers .= 'Cc:'. $email . "
";
$reply = "";

/* This is what sends the email */
$success = mail($webMaster, $body, $headers, "-f $email");


/* Results Rendered as Html */



header('location:thankyou.php');exit;
?>

</div>
  • 写回答

3条回答 默认 最新

  • 普通网友 2015-10-27 07:38
    关注

    Check below code for each page

    Page1

    <html>
    <body  bgcolor="#fff" text="#000" >
    <form method="post" action="page2.php">
    <p>Which car you want to buy?<P>
    <TABLE border="1" width="500">
    <TR ><TD><input type="checkbox" value ="ferrari"  name="brand[]"><TD>Ferrari</td></TR>
    <TR><TD><input type="checkbox" value ="mercedes"  name="brand[]"><TD>Mercedes</td></TR>
    <TR><TD><input type="checkbox" value ="bugatti"  name="brand[]"><TD>Bugatti</td></TR>
    </TABLE>
    <input type="hidden" value="1" name="car_brand" >
    <p>
    <input type="submit" value="Continue" >
    </form>
    </body>
    

    Page2

    In this page I used implode function for convert array to string

    <html>
    <body  bgcolor="#fff" text="#000" >
    
    <div id="firstpage-value" style="border:1px solid #000;">
    <h4>Selected Brand</h4>
    <?php
    if(isset($_POST['car_brand']))
    {   
        $count=count($_POST['brand']);
        for($i=0;$i<$count;$i++)
        {
            echo $_POST['brand'][$i]." ";
        }
        $brand = implode("," ,$_POST['brand']);
    }
    ?>
    </div>
    
    <form method="post" action="mail.php">
    <p>Choose a Price Range<P>
    <TABLE border="1" width="500">
    <TR ><TD><input type="checkbox" value ="under20k"  name="price[]"><TD>Under $20K</td></TR>
    <TR><TD><input type="checkbox" value ="35-85k"  name="price[]"><TD>$35K-$85K</td></TR>
    <TR><TD><input type="checkbox" value ="over85k"  name="price[]"><TD>Over $85K</td></TR>
    </TABLE>
    <input type="text" name="email" value="email" />
    <input type="hidden" value="1" name="car_price" >
    <p>
    <input type="submit" value="Submit" >
    
    <input type="hidden" name="brand" value="<?php  echo $brand; ?>">
    </form>
    </body>
    </html>
    

    mail page

    <?php 
    
    
    
    /* Subject and email variables */
    
    $emailsSubject = 'Brochure Request';
    $thanks = 'Thank you for requesting Brochure';
    $webMaster  = 'mailsample@gmail.com';
    $mailheader .= "Reply-To: ".$_POST["email"]."
    ";
    
    //Get the input.
     $email = $_POST['email'];
    $brand = $_POST['brand'];
    $price = implode(",",$_POST['price']); 
    
    
    $body = '
    <p>A user has been submitted "Request Brochure" form with the following info.</p>
    <table width="600" border="1" >
          <tr>
          <th width="556" height="37" align="left"><h2>Which car you want to buy?</h2></th>
          <th width="268" style="border-bottom:1px solid #ccc; ">'.$brand.'</th>
        </tr>
        <tr>
          <th width="556" height="37" align="left"><h2>Choose price range</h2></th>
          <th width="268" style="border-bottom:1px solid #ccc; ">'.$price.'</th>
        </tr>
    
        <tr>
          <th width="556" height="37" align="left"><h2>Email Address</h2></th>
          <th width="268" style="border-bottom:1px solid #ccc; ">'.$email.'</th>
        </tr>   
        ';
    
    
        $headers = "From: $email
    ";
    $headers .= "Content-type: text/html
    ";
    $headers .= 'Cc:'. $email . "
    ";
    $reply = "";
    
    /* This is what sends the email */
    $success = mail($webMaster, $body, $headers, "-f $email");
    
    
    /* Results Rendered as Html */
    
    
    
    header('location:thankyou.php');exit;
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题