Ok so I want people to fill in a form and when they press submit it gets sent to my email address... Everything is working fine I just need to know how to make the checkbox appear in my email, the free script I used didn't have any checkbox and I don't know how to write them

Here's my PHP code:

<?php 
if(isset($_POST['email'])) {
	
	// EDIT THE 2 LINES BELOW AS REQUIRED     
	$email_to = "mymail";     
	$email_subject = "Un nouveau formulaire est rempli";  
	

	function died($error) {         
	// your error code can go here        
	echo "Il semble y avoir une erreur avec le formulaire que vous tentez d'envoyer.";         
	echo "Voici ces erreurs:.<br /><br />";        
	echo $error."<br /><br />";         
	echo "Merci de les corriger avant de tenter de renvoyer le formulaire.<br /><br />";         
	die();     
	}           
	
	// validation expected data exists     
	if(!isset($_POST['prenom']) ||         
					 !isset($_POST['nom']) ||   
					 !isset($_POST['sexe']) || 
					 !isset($_POST['telephone']) ||      
					 !isset($_POST['email']) ||      
					 !isset($_POST['experience'])) {      
	died('Il semble y avoir une erreur avec le formulaire que vous tentez d\'envoyer.');           
	}  
	
	$prenom = $_POST['prenom']; // required 
	$nom = $_POST['nom']; // required  
	$sexe = $_POST['sexe']; // not required
	$telephone = $_POST['telephone']; // not required
	$email = $_POST['email']; // required   
	$experience = $_POST['experience']; // required     
	
	$error_message = "";     
	$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';   
	if(!preg_match($email_exp,$email)) {    
	$error_message .= 'Votre adresse courriel est invalide.<br />';      
	}
	if(strlen($experience) < 2) {     
	$error_message .= 'Veuillez écrire votre expertise dans la section réversée à cette fin.<br />';   
	}   
	if(strlen($error_message) > 0) {     
	died($error_message);   
	}     $email_message = "Formulaire rempli:.\n\n";           
	
	function clean_string($string) {       
	$bad = array("content-type","bcc:","to:","cc:","href");       
	return str_replace($bad,"",$string);     
	}          
	
	$email_message .= "Prenom: ".clean_string($prenom)."\n";     
	$email_message .= "Nom: ".clean_string($nom)."\n";
	$email_message .= "Sexe: ".clean_string($sexe)."\n";
	$email_message .= "Telephone: ".clean_string($telephone)."\n";
	$email_message .= "Courriel: ".clean_string($email)."\n";  
	$email_message .= "Experience et Expertise: ".clean_string($experience)."\n";    
	
	// create email headers 
	$headers = 'From: '.$email."\r\n". 
	'Reply-To: '.$email."\r\n" . 
	'X-Mailer: PHP/' . phpversion(); 
	@mail($email_to, $email_subject, $email_message, $headers);   
	?><!-- include your own success html here -->  Merci d'avoir pris le temps de remplir le formulaire! Nous vous contacterons le plus rapidement possible.  <?php } ?>

Here's my HTML:

<form id="DevenirBenevole" name="DevenirBenevole" method="post" action="scripts/benevoleformulaire.php">
  <table width="90%" border="0" cellspacing="0" cellpadding="5" align="center">
    <tr>
      <td width="45%" align="right" class="TxtContenuRight"><label>Prénom:</label></td>
      <td width="55%" align="left"><input type="text" name="prenom" id="prenom" /></td>
      </tr>
    <tr>
      <td width="45%" align="right" class="TxtContenuRight"><label>Nom:</label></td>
      <td width="55%" align="left"><input type="text" name="nom" id="nom" /></td>
    </tr>
    <tr>
      <td align="right" class="TxtContenuRight"><label>Je suis:</label></td>
      <td align="left"><span class="TxtContenuRight">
      <select name="sexe" size="1" class="TxtContenu" id="sexe">
        <option value="homme" selected="selected">un homme</option>
        <option value="femme">une femme</option>
      </select>
      </span></td>
    </tr>
    <tr>
      <td width="45%" align="right" class="TxtContenuRight"><label>Numéro de téléphone:</label></td>
      <td width="55%" align="left"><input type="text" name="telephone" id="telephone" /></td>
    </tr>
    <tr>
      <td align="right" class="TxtContenuRight"><span class="TxtContenu">Courriel:
          
      </span></td>
      <td align="left"><input type="text" name="email" id="email" /></td>
    </tr>
    <tr>
      <td width="45%" align="right" valign="top" class="TxtContenuRight"><table width="66%" border="0" align="right" cellpadding="0" cellspacing="0">
          <tr>
            <td height="auto" class="TxtContenuRight">Veuillez cocher les domaines qui vous intéresse le plus:</td>
          </tr>
        </table></td>
      <td width="55%" align="left" valign="top"><p class="TxtContenu">
        <label>
          <input type="checkbox" name="DomaineInteret" value="checkbox" id="Accueil" /></label>
        <span class="TxtContenuBold">Accueil </span><br />
      <br />
          <label>
            <input type="checkbox" name="DomaineInteret" value="checkbox" id="ComiteDeveloppement" />
            <span class="TxtContenuBold">Comité de développement</span></label>
          <br />
<br />
          <label>
            <input type="checkbox" name="DomaineInteret" value="checkbox" id="ComiteFinance" />
            <span class="TxtContenuBold">Comité de finances </span></label>
          <br />
          <br />
          <label>
            <input type="checkbox" name="DomaineInteret" value="checkbox" id="ComiteCulturel" />
            <span class="TxtContenuBold">Comité Culturel </span></label>
          <br />
          <br />
          <label>
            <input type="checkbox" name="DomaineInteret" value="checkbox" id="ComiteSocial" /></label>
          <span class="TxtContenuBold">Comité Social </span><br />
          <br />
          <label>
            <input type="checkbox" name="DomaineInteret" value="checkbox" id="ComiteProgrammation" />
            <span class="TxtContenuBold">Comité de Programmation</span><br />
          </label>
          <br />
          <label>
            <input type="checkbox" name="DomaineInteret" value="checkbox" id="ComiteVoyages" />
            <span class="TxtContenuBold">Comité de Voyages et Sorties</span></label>
          <br />
          <br />
          <label>
            <input type="checkbox" name="DomaineInteret" value="checkbox" id="ComiteChorale" />
            <span class="TxtContenuBold">Comité de la Chorale </span></label>
          <br />
          <br />
          <label>
            <input type="checkbox" name="DomaineInteret" value="checkbox" id="ComiteBridge" /></label>
          <span class="TxtContenuBold">Comité de bridge </span><br />
          <br />
          <label>
            <input type="checkbox" name="DomaineInteret" value="checkbox" id="BingoFriends" />
            <span class="TxtContenuBold">Bingo Friends</span><br />
          </label>
          <br />
          <label>
            <input type="checkbox" name="DomaineInteret" value="checkbox" id="25eme" />
            <span class="TxtContenuBold">25ième anniversaire du CSMO </span></label>
          <br />
        </p></td>
    </tr>

Thank you very much for your help!

Your syntax on your checkbox inputs are incorrect.
Try this on your form code for each of the checkbox fields:

<input type="checkbox" name="DomaineInteret[]" value="25eme" />
<input type="checkbox" name="DomaineInteret[]" value="BingoFreinds"  />
// and so on, the checkboxes you have are part of a 'group' and therefore you want
// the [] on the end of each name.  (these come across in an array for processing.
$checkbox_html = '';
  // lets process them now.
  $checkboxes = $_POST['DomaineInteret'];
  if(empty($checkboxes)) {
    echo("You didn't select any checkboxes.");
    $checkbox_html = 'No checkboxes selected';
  } else {
    $N = count($checkboxes);
     echo("You selected $N checkboxe(s): ");
     for($i=0; $i < $N; $i++) {
        echo($checkboxes[$i] . " ");
        // instead of echoing you could.. 
        $checkbox_html .= $checkboxes[$i]. "\n";
     }
  }

//  and finally around line 58 of your current code:
$email_message .= "checkboxes checked:\n". $checkbox_html;

It still doesn't work...

I receive an email and where there should be the selected checkboxes there is only a "c"...

Might you know how to correct this?

EDIT: Or maybe is it me that is placing the code somewhere I shouldn't? Where exactly was I suppose to put your new coding?

the first part of the post was information for you to change on your html page.
every <input type="checkbox"

<input type="checkbox" ...

code needs to be updated throughout your html. change the value= field to be the value of the field currently held in id=. So remove id code, and make the value of those checkboxes whatever is currently in the id= field see sample in original post.

The php syntax will go somewhere in your php code to pull out the results of all items that were checked.

So, update all of your html checkbox input lines with the correct syntax as described in first post. Then add all of the PHP code right after line 58 of your php script.

Works great!!

Thank you very much you have made pretty much my whole week!

Actually, would it be possible not to show which checkboxes were checked? Like remove the echo? It would be great to have this function with another context but with what I'm trying to do it would only confuse people...

Thanks and sorry for asking some many questions!

Certainly remove the echos. They were only there so you could see what was happening at that point. No need to confuse anybody... edit the code to do whatever it is you need it to do, it's yours now.

Thanks again it works perfectly!!

EDIT: I found the answer to my question, thanks anyway!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.