简单邮件与复选框时事通讯 - 我做错了什么? 一切都好 - 发送信息exept复选框 请帮忙
<?php
if ( isset($_POST['email']) && isset($_POST['name']) && isset($_POST['subject']) && isset($_POST['text']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
$test = "/(content-type|bcc:|cc:|to:)/i";
foreach ( $_POST as $key => $val ) {
if ( preg_match( $test, $val ) ) {
exit;
}
}
$message .= "<strong>Client:</strong>" . strip_tags($_POST['name']) . ;
$message .= "<strong>E-mail:</strong>" . strip_tags($_POST['email']) . ;
$message .= "Newsletter" . strip_tags($_POST['newsletter']) ;
$to = 'aaa@gmailcom';
$subject = $_POST['subject'];
$headers = "From: " . $_POST['email'] . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8\r\n";
mail($to, $subject, $message, $headers);
}
?>
和html
<label for="newsletter">
<input type="checkbox" id="newsletter" name="newsletter" value="Yes" checked> Subscribe
</label>
答案 0 :(得分:0)
$ _ POST ['newsletter']仅在选中复选框时才存在。
您可以尝试这样的事情
<?php
$info = "";
if(isset($_POST['newsletter'])){
$info = "You want to receive the newsletter";
}
else{ $info = "You dont want the newsletter"; }
$message .= "Newsletter :" . $info ;
?>
希望这有帮助 ps:使用var_dump($ _ POST)调试发布的数据