I hope someone could help me on this. Everything is working well, from filling up the html form, sending for validation and redirect to thank you form of my website, and e-mail is successfully received, with the data validated except for the choices in the check boxes which are never shown in the e-mail.
Here is my HTML code:
<form method="POST"
action="mydomain/send.php">
<input type="hidden" name="mailto"
value="myemail@mydomain.com"><!-- ... -->
<input type="hidden" name="thanksurl"
value="mydomain/thankyouform.html"><!--
... -->
<p><font color="#0000FF"><b>Please fill-up this form to send us your inquiry</b></font></p>
<br />
<table cellpadding="2" cellspacing="0" border="1" bgcolor="#dbcbb2">
<tr valign="top">
<td><font face="Verdana" size="2" color="#000000"> Name </font></td>
<td><input type="text" name="Name" size="30"></td>
</tr>
<tr valign="top">
<td><font face="Verdana" size="2" color="#000000"> Address </font></td>
<td><input type="text" name="Address" size="30"> </td>
</tr>
<tr valign="top">
<td><font face="Verdana" size="2" color="#000000"> Email </font></td>
<td><input type="text" name="E-Mail Address" size="30"> </td>
</tr>
<tr valign="top">
<td><font face="Verdana" size="2" color="#000000">Interested in </font></td>
<td><input type="text" name="Interested in" size="30" value="Tuscania CDO" readonly="readonly"></td>
</tr>
<tr valign="top">
<td><font face="Verdana" size="2" color="#000000"> Click Box of <br /> Chosen Unit</font></td>
<td>
<div align="left">
<input type="checkbox" name="option1" value="Amalfi"> Amalfi
<input type="checkbox" name="option2" value="Capri"> Capri
<input type="checkbox" name="option3" value="Genova"> Genova
<input type="checkbox" name="option4" value="Verona I"> Verona I <br />
<input type="checkbox" name="option5" value="Verona II"> Verona II
<input type="checkbox" name="option6" value="Treviso"> Treviso
<input type="checkbox" name="option7" value="Special Design"> Special Design <br />
<input type="checkbox" name="option7" value="New Design"> New Design
</div>
</td>
<tr valign="top">
<td><font face="Verdana" size="2" color="#000000"> Your Inquiry </font></td>
<td><textarea name="Inquiry" cols="40" rows="4"></textarea><br> </td>
</tr>
<tr>
<td colspan="2"><input type="submit" class="btn" value="Send Email" name="Submit"> <input type="reset" class="btn" value=" Clear " name="Clear"></td>
</tr>
</table>
</form>
My PHP Script:
<?php
// Clean up the input values
foreach($_POST as $key => $value) {
if(ini_get('magic_quotes_gpc'))
$_POST[$key] = stripslashes($_POST[$key]);
$_POST[$key] = htmlspecialchars(strip_tags($_POST[$key]));
}
// Assign the input values to variables for easy reference
$name = $_POST["name"];
$address = $_POST["address"];
$email = $_POST["email"];
$confirm = $_POST["confirm_email"];
$interested_in = $_POST["interested_in"];
$option = $_POST["option"];
$option = implode(', ', $option);
$message = $_POST["message"];
// Send the email *********** enter your email address and message info *******************
$to = "myemail@mydomain.com";
$subject = "Website message: $name";
$message = "From:\
$name\
\
Address:\
$address\
\
Email:\
$email\
\
Interested_in:\
$interested_in\
\
Option:\
&option\
\
Message:\
$message";
$headers = "From: $email";
mail($to, $subject, $message, $headers);
if(!empty($_POST["confirm_email"])) {
$response = array(
"success" => true,
"content" => "<span class='success'><li>Thank you!</li></span>"
);
die(json_encode($response));
}
/* Redirect visitor to the thank you page */
header('Location: mydomain/thankyouform.html');
exit();
?>
The JSCRIPT:
/*--validation--*/
$(function() {
function validateform() {
var valid = true;
$(".req").css("border","1px solid green");
$(".req").each(function() {
if($(this).val() == "" || $(this).val().replace(/\\s/g, '').length == 0) {
$(this).css("border","1px solid red");$(".required").css("display","block");
valid = false;
}
});
return valid;
}
$("#submit").click(function() {
$('#myform').submit(validateform);
$('$name').submit();
});
});
Thank you in advance. Further, may I know if the PHP script, safe for spammers and hackers?