2016-09-15 7 views
-2

Hallo ich bin neu bei PHP und ich brauche Hilfe mit meinem Code.Send checkbox value

Das Problem: Ich möchte eine Mail mit Checkbox-Werten senden, wenn sie überprüft werden, aber ich kann nicht, und ich weiß nicht, wie Sie dieses Problem lösen.

Hier ist mein Code.

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 = '[email protected]'; // Add your email address inbetween the '' replacing [email protected] - 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: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected] 
$headers .= "Reply-To: $email_address"; 
mail($to,$email_subject,$email_body,$headers); 
return true; 
?> 

Antwort

0

Versuchen Sie, diese

<?php 
foreach($_POST['time'] as $value) 
    { 
    echo 'checked: '.$value.''; 
    // insert your email code here 
    } 
?> 
+0

Ich versuche es, aber nach dem Klicken auf senden bekomme ich Fehlermeldung: Keine Argumente zur Verfügung gestellt! –

+0

@MaxSadowski - Nun, das hat nichts mit den Checkboxen zu tun. Das ist dein Test am Anfang des PHP-Abbruchs. – Quentin

0

Ok ich es gefunden! :)

<?php 
    $name = $_POST['name']; 
    $email = $_POST['email']; 
    $phone = $_POST['phone']; 
    $message = $_POST['message']; 
    $time = nl2br(implode(',', $_POST['time'])); 

    $to = '[email protected]'; // Add your email address inbetween the '' replacing [email protected] - 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: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected] 
    $headers .= "Reply-To: $email"; 
    mail($to,$email_subject,$email_body,$headers); 

?> 

Die Lösung war $ time = nl2br (implodieren (' ' $ _POST [' Zeit'])); Gefunden Here