查询页面中的多项选择 - 邮件功能

时间:2017-04-20 19:09:26

标签: php multipleselection mailing

实际上我在一个查询页面上工作,我有多个选择选项,一旦用户选择多个选项并提交表格,我想在邮件上找到它。为此,我已经完成了以下代码,但未能理解问题,请帮助我的朋友......

这是HTML代码

<select id="lstFruits" name="product_drop[]" multiple="multiple">
<option value="Orange Color ">Orange Color </option>
<option value="Red  Color">Red Color</option>
<option value="Black Color">Black Color</option>
<option value="Purple Color">Purple Color</option>
</select> 

我在下面的代码中使用了一个用于邮件功能的PHP代码,它正在工作,其他字段如name,no,cname,mail&amp;消息正在接收邮件,但只有这个多选的东西不会收到邮件。 prod = implode无效..

<?php
$name    =  trim($_POST['name']);
$no    =  trim($_POST['no']);
$cname  =  trim($_POST['cname']);
$mail     =  trim($_POST['mail']);
$mess   =  trim($_POST['message']);

if(isset($_POST['product_drop']))
{
$prod=implode(',',$_POST['product_drop']);
}


$redirect_to = 'https://www.google.com';
$a="";

$to = "email@gmail.com";
$subject = "Enquiry Received from Website";
$message = "Name: " . $name ."\r\nContact No.: " . $no ."\r\nCompany Name: "
. $cname . "\r\nMessage: " . $mess . "\r\nProduct: " . $prod."";    

$from = "Website";
$headers = "From:" . $from . "\r\n";
$headers .="Cc: ". $a . "\r\n";


$headers .= "Content-type: text/plain; charset=UTF\n";


if(@mail($to,$subject,$message,$headers))
{
    header("Location: $redirect_to");
    exit;
}
?>

提前致谢!!!

1 个答案:

答案 0 :(得分:0)

你只是退一步继续工作兄弟

<form method="post" action="">
<select id="lstFruits" name="product_drop[]" multiple="multiple">
<option value="Orange Color ">Orange Color </option>
<option value="Red  Color">Red Color</option>
<option value="Black Color">Black Color</option>
<option value="Purple Color">Purple Color</option>
</select> 
<input type="submit">
</form>
<?php
if($_POST){
$array = array(); // Define it array
$array = $_POST['product_drop']; /// This will be Array
$values = implode(",", $array);
echo $values; // Work Done 
}
?>