Hi everyone,
I'm trying to pass checkbox values to the PHP mail function. I've setup XAMPP and got the mail function to work before. Here is my html code below:
<body>
<div class="container">
<!-- Feedback Form Starts Here -->
<div id="feedback">
<!-- Heading Of The Form -->
<div class="head">
</div>
<!-- Feedback Form -->
<form action="secure_email_code.php" class="form-design col-md-4" method="post" name="form">
<h1>What's Your CO<span class="subscript">2</span> Emission?</h1>
<input name="vname0" placeholder="Your First Name" type="text" value=""><br>
<input name="vname1" placeholder="Your Last Name" type="text" value=""><br>
<input name="vemail" placeholder="Your Email" type="text" value=""><br>
<!--input name="sub" placeholder="Subject" type="text" value=""><br-->
<!--<textarea name="msg" placeholder="Type your text here..."></textarea><br>-->
<h2 >Questions</h2><br>
<label>Fast Food?</label>
<input type="checkbox" value="1" name="cbox[]"><br>
<label>Home Made?</label>
<input type="checkbox" value="2" name="cbox[] "><br>
<input id="send" name="submit" type="submit" value="Send Feedback"><br>
</form>
</div>
<!-- Feedback Form Ends Here -->
</div>
</body>
My PHP code is echoing the results. Except for the mail function. Now, here is my php code below:
<?php
if(isset($_POST["submit"])){
//Checking For Blank Fields..conditional
if($_POST["vname0"]==""||$_POST["vname1"]==""||$_POST["vemail"]==""|| (empty($_POST['cbox']) ) ){
echo "<h1>Fill All Fields..</h1>";
}
else{
// Check if the "Sender's Email" input field is filled out
$email=$_POST['vemail'];
$name0=$_POST['vname0'];
$name1=$_POST['vname1'];
$name= array($name0, $name1);
// Sanitize E-mail Address
$email =filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate E-mail Address
$email= filter_var($email, FILTER_VALIDATE_EMAIL);
if (!$email){
echo "Invalid Sender's Email";
}
//$subject = $_POST['sub'];
//for (init counter; test counter; increment counter) {
// code to be executed for each iteration;
//}
// init counter: Initialize the loop counter value
// test counter: Evaluated for each loop iteration. If it evaluates to TRUE, the loop continues. If it evaluates to FALSE, the loop ends.
//increment counter: Increases the loop counter value
//foreach($_POST['check'] as $value) {
// $check_msg .= "Checked: $value\n";
//}
foreach($_POST['cbox'] as $value){
if($value == 1){
$value =
"
<h2>Fast Food</h2>
<p>The stuff that kills.</p>
";
echo " $name[0] selected: $value\n ";
} elseif ($value == 2) {
$value =
"
<h2>Home Made</h2>
<p>Yum! There is nothing like a home cooked meal!</p>
";
echo " $name[0] selected: $value\n ";
}
$body = "CFP Results\r\n From: $name[0] $name[1]\r\n, Email: $email\r\n, Results: $value\r\n";
}
$to = "franklin120889@gmail.com";
mail($to, "CFP_DATA", $body, $email);
//$message = wordwrap($message, 70);
// Send Mail By PHP Mail Function
}
}
?>