如何为电子邮件中的复选框和回显发送多个值?

时间:2011-03-25 11:31:47

标签: php javascript html

当我尝试“勾选”多个复选框时,页面将停止。

可能是我不知道的编码错误

form.php的

<tr>
    <td><input type="checkbox" name="color[]"  value="YK GI ZincCoat&trade;"> YK GI ZincCoat&trade;</td>
    <td><input type="checkbox" name="color[]"  value="YK ColourCoat&trade;"> YK ColourCoat&trade;</td>
  </tr>
  <tr>
    <td><input type="checkbox" name="color[]" value="YK WarnaCanggih&trade; ColourCoat "> YK WarnaCanggih&trade; ColourCoat </td>
    <td><input type="checkbox" name="color[]" value="YK Self Cleaning&trade; ColourCoat"> YK Self Cleaning&trade; ColourCoat </td>
  </tr>

process.php

<?php


    $first= $_GET["first"];
    $job= $_GET["job"];
    $nature= $_GET["nature"];
    $color[]= $_GET["color[]"];
    $name= $_GET["name"];
    $jobtitle= $_GET["jobtitle"];
    $Company= $_GET["Company"];
    $address1= $_GET["address1"];
    $Tel= $_GET["Tel"];
    $Fax= $_GET["Fax"];
    $Handphone= $_GET["Handphone"];
    $Email= $_GET["Email"];





    require_once('lib/class.phpmailer.php');

    $mail             = new PHPMailer(); // defaults to using php "mail()"


    $mail->AddReplyTo("ruslyrossi46@gmail.com","rusly");

    $mail->SetFrom('ruslyrossi46@gmail.com', 'rusly');

    $mail->AddReplyTo("ruslyrossi46@gmail.com","rusly");

    $address = "ruslyrossi46@gmail.com";
    $mail->AddAddress($address, "rusly");

    $mail->Subject    = "Starshine Group - Enquiry Form";

    $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

    $mail->Body = "Contact Us<br><br> 
    $first<br>
    job : $job<br>
    nature : $nature<br><br>
    Product Interest : $color[]<br>
    First Name : $name<br>
    Job Title : $jobtitle<br>
    Address : $address1<br> 
    Company : $Company<br> 
    Phone Number : $Tel<br> 
    Handphone : $Handphone<br>
    Email : $Email<br> 
    Fax : $Fax<br> 

    Thank You!<br>


    ";


    if(!$mail->Send()) {
      echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
      echo "
    First Name : $name<br>
    Address : $address1<br> 
    Phone Number :  $Tel<br> 
    Email : $Email<br> 


    Thank You!<br><br>

      Message sent!<br>";
    }

    ?>

3 个答案:

答案 0 :(得分:3)

使用$color= $_GET["color"];代替$color[]= $_GET["color[]"];

$ color将是值数组。

并使用

Product Interest : ".implode(',', $color)."<br>  // this will add in format of value1,value2,value3  you can change comma to any other char

而不是Product Interest : $color[]<br>

答案 1 :(得分:0)

试试这个

<?php

$first= $_GET["first"]; $job= $_GET["job"]; $nature= $_GET["nature"]; $color[]= $_GET["color"]; $name= $_GET["name"]; $jobtitle= $_GET["jobtitle"]; $Company= $_GET["Company"]; $address1= $_GET["address1"]; $Tel= $_GET["Tel"]; $Fax= $_GET["Fax"]; $Handphone= $_GET["Handphone"]; $Email= $_GET["Email"];

require_once('lib/class.phpmailer.php');

$mail = new PHPMailer(); // defaults to using php "mail()"

$mail->AddReplyTo("ruslyrossi46@gmail.com","rusly");

$mail->SetFrom('ruslyrossi46@gmail.com', 'rusly');

$mail->AddReplyTo("ruslyrossi46@gmail.com","rusly");

$address = "ruslyrossi46@gmail.com"; $mail->AddAddress($address, "rusly");

$mail->Subject = "Starshine Group - Enquiry Form";

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->Body = "Contact Us

$first
job : $job
nature : $nature

Product Interest : ";
foreach($color as $k=>$val){
    $mail->Body .= $val.', ';
}
 "First Name : $name
Job Title : $jobtitle
Address : $address1
Company : $Company
Phone Number : $Tel
Handphone : $Handphone
Email : $Email
Fax : $Fax
Thank You!

";

if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo " First Name : $name
Address : $address1
Phone Number : $Tel
Email : $Email
Thank You!


Message sent!
"; }

?>

答案 2 :(得分:0)

    if($_REQUEST[color]){
        $color=$_REQUEST[color];
    }else{
        $color=array();     
    }
    $totalcolor=implode(",", $_REQUEST[color]);

首先在您的页面上设置此项,然后请求$ totalcolor值,其中包含所有颜色的值,确定是否正常。