我正在尝试发布多项选择的值,而我只获得'数组'而不是电子邮件中的值。
我的选择如下:
<select name="cate[]" class="form-control selectpicker" multiple>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
我的php:
$val= $_POST['val'];
$toemail='test@mail.com'; // change this to your email id
$name = $val['name'];
$societe = $val['societe'];
$email = $val['email'];
$phone = $val['phone'];
$website = $val['website'];
$category = $val['cate'];
$msg = $val['msg'];
$subject = 'Contact';
$headers = "From: $email \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<b>Nom : </b>".$name."<br>";
$message .='<b>Societe : </b>'.$societe."<br>";
$message .='<b>Email : </b>'.$email."<br>";
$message .='<b>Telephone : </b>'.$phone."<br>";
$message .='<b>Category : </b>'.$category."<br>";
$message .='<b>Message :</b>'.$msg;
mail($toemail, $subject, $message, $headers);
echo "Thanks!";
我错过了什么?提前致谢。
答案 0 :(得分:1)
由于$val['cate']
是一个数组,因此需要将其转换为字符串。使用代码执行此操作的最快方法是:
$category = implode(', ', $val['cate']);