I have this form that includes checkboxes. And I want a mail to be sent on submission of the form with the value of the checked checkbox og checkboxes. but the code doesn't work. Any help?
It tells me on submission that the form was submitted successfully and not including any errors. But I don't receive the email.
<form id="contact-form" method="POST" action="contact-form-handle.php">
<h3 class="contact-im">I'm interested in. . .</h3>
<div class="interested-container">
<div class="checkbox-frame">
<input class="checkbox_form" type="checkbox" name="category[]" id="PHOTOGRAPHY" value="PHOTOGRAPHY"><br>
<label class="form-label" for="PHOTOGRAPHY">PHOTOGRAPHY</label>
</div>
<div class="checkbox-frame">
<input class="checkbox_form" type="checkbox" name="category[]" id="GRAPHIC-DESIGN" value="GRAPHIC-DESIGN"><br>
<label for="GRAPHIC-DESIGN">GRAPHIC DESIGN</label>
</div>
<div class="checkbox-frame">
<input class="checkbox_form" type="checkbox" name="category[]" id="LIVE-INSTALLATION" value="LIVE"><br>
<label for="LIVE-INSTALLATION">LIVE INSTALLATION</label>
</div>
<div class="checkbox-frame">
<input class="checkbox_form" type="checkbox" name="category[]" id="VIDEOGRAPHY" value="VIDEOGRAPHY"><br>
<label for="VIDEOGRAPHY">VIDEOGRAPHY</label>
</div>
<div class="checkbox-frame">
<input class="checkbox_form" type="checkbox" name="category[]" id="PERSONAL-PROJECTS" value="PERSONAL-PROJECTS"><br>
<label for="PERSONAL-PROJECTS">PERSONAL PROJECTS</label>
</div>
<div class="checkbox-frame">
<input class="checkbox_form" type="checkbox" name="category[]" id="OTHER" value="OTHER"><br>
<label for="OTHER">OTHER</label>
</div>
</div>
<input name="name" type="text" class="form-control" placeholder="Name / Company. . ." required>
<br>
<input name="email" type="email" class="form-control" placeholder="Email. . ." required>
<br>
<textarea name="message" class="form-control" rows="4" placeholder="Message. . ." required></textarea>
<br>
<input type="submit" class="form-control submit" value="Submit ">
</form>```
and the php:
```<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
if(!empty($_POST["category"])) //check if the user has selected a CHECKBOX or NOT
{
$checkbox =$_POST["category"]; //Array of values from the checkbox
foreach($checkbox as $value) //loop to store and display values of individual checkboxes
{echo $value;}} //Display selected checkbox
else {test_input($_POST["value"]);
}
$mailheader = "From:".$name."<".$email.">\r\n";
$reciepient = "mathiasqm@gmail.com";
mail($reciepient, 'Website Lead Gen', $message, $mailheader, $value)
or die("Error!");
echo'Message successfully submitted';
?>```
Aucun commentaire:
Enregistrer un commentaire