您好我是PHP的新手,我需要一些帮助我的代码。
问题:我想发送带有复选框值的邮件,如果选中它们,但我不能,而且我不知道如何解决这个问题。
这是我的代码。
HTML
<div class="form-group">
<label for="jours">Choix des jours de travail</label>
<label class="checkbox">
<input type="checkbox" name="time[]"value="Lundi"> Lundi
</label>
<label class="checkbox">
<input type="checkbox" name="time[]"value="Mardi"> Mardi
</label>
<label class="checkbox">
<input type="checkbox" name="time[]"value="Mercredi"> Mercredi
</label>
<label class="checkbox">
<input type="checkbox" name="time[]"value="Jeudi"> Jeudi
</label>
<label class="checkbox">
<input type="checkbox" name="time[]"value="Vendredi"> Vendredi
</label>
<label class="checkbox">
<input type="checkbox" name="time[]"value="Samedi"> Samedi
</label>
</div>
PHP
<?php
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$message = strip_tags(htmlspecialchars($_POST['message']));
// Create the email and send the message
$to = 'maxmaxstudio2@gmail.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form: $name";
$email_body = "Vous avez recu un nouveau message\n\n"."Voici les détails:\n\nName: $name\n\nEmail: $email_address\n
\nPhone: $phone\n\nMessage:\n$message\n\nThe client want help in these days: $time\n";
$headers = "From: maxmaxstudio2@gmail.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
答案 0 :(得分:0)
试试这个
<?php
foreach($_POST['time'] as $value)
{
echo 'checked: '.$value.'';
// insert your email code here
}
?>
答案 1 :(得分:0)
好的我找到了! :)
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$time = nl2br(implode(',', $_POST['time']));
$to = 'maxmaxstudio2@gmail.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to.
$email_subject = "Demande d'aide-ménagère: $name";
$email_body =
"Vous avez recu un nouveau message de:$name\n
\n"."Voici les détails:\n
Nom: $name\n
Email: $email\n
Téléphone: $phone\n
Message:\n$message\n
\nThe client want help in these days: $time";
$headers = "From: maxmaxstudio2@gmail.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.
$headers .= "Reply-To: $email";
mail($to,$email_subject,$email_body,$headers);
?>
解决方案是$ time = nl2br(implode(',',$ _POST ['time'])); 找到它Here