Hi all,
I have a form mailer script which I have used many times along with jquery validation. I have had recent spamming issues so I would like to add some server side validation to back the javascript up.
This is the PHP (also attached)
<?PHP
#*********************************************************************************************#
# Universal PHP mailer script
#*********************************************************************************************#
# Date: 05/05/05
# Written by: Some Guy
# Email: [email]whatever@biscuits.com[/email]
#*********************************************************************************************#
#------------------------------- Set the intial variables below ------------------------------#
$to = "name@email.com"; // This is the recipients email address
$from = "name@email.comk"; // this appears in the from field must be in email format
$subject = "Contact from the website"; // This is the email subject header
$forward = 1; // 1= web forwarding on 0 = forwarding off
$location = "thankyou.php"; // enter forwarding address here e.g. "thankyou.htm"
$formMsg = "Someone has filled in the contact form on the website, the results are below."; //This message appears in the top cell
$colour1 = "#D6C6FC"; // Insert a colour in here for the top cell of the table
$colour2 = "#E1D6FD"; // Insert a colour in here for the left cells
$colour3 = "#E8DFFD"; // Insert a colour for the right cells
$textcolour = "#444444"; //insert a value for text colour
$textsize = "13"; //text size in pixels
$logoUrl = "http://www.site.com/images/logo.png"; // Absolute URL for logo image top left
$logoAlt = "Company name"; //alt tag on logo
//------------ Do not Edit below this line unless you know what you are doing ----------------#
$date = date ("l, F jS, Y");
$time = date ("h:i A");
$msg = "<html><head><style type='text/css'>td {font-family: Arial, Helvetica, sans-serif;font-size: $textsize px; color: $textcolour;text-decoration: none;}</style></head><body><div align=center><table border=0 cellpadding=10 cellspacing=1 width=500>";
$msg .= "<tr><td colspan=2 width=400 bgcolor='white' align=left valign=top><img src=\\"$logoUrl\\" alt=\\"$logoAlt\\"></td></tr>";
$msg .= "<tr><td colspan=2 width=400 bgcolor='$colour1'><b>$formMsg</b> <br>This form was submitted on $date at $time.<br></td></tr>";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) {
$msg .= "<tr><td width=150 bgcolor='$colour2' align=left valign=top>".ucfirst ($key) ."</td><td width=250 bgcolor='$colour3' align=left valign=top>". $value . "</td></tr>";
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= "<tr><td width=350 bgcolor='$colour2' align=left valign=top>".ucfirst ($key) ."</td><td width=250 bgcolor='$colour3' align=left valign=top>". $value . "</td></tr>";
}
}
$msg .= "</table></div></body></html>";
$headers = "From: $from\\r\
";
// specify MIME-Version 1.0
$headers .= "MIME-Version: 1.0\\r\
";
//unique boundary
$boundary = uniqid("KCMAIL");
//tell e-mail client this email contains alternative versions
$headers .= "Content-Type: multipart/alternative".
"; boundary = $boundary\\r\
\\r\
";
//mesage to non mime type browsers
$headers .= "This is a MIMe encoded message. Please update your email browser.\\r\
\\r\
";
//plain text version of message
$headers .= "--$boundary\\r\
".
"Content-Type: text/plain; charset=ISO-8859-1\\r\
" .
"Content-Transfer-Encoding: base64\\r\
\\r\
";
$headers .= chunk_split(base64_encode("This is the plain version"));
//Html version
$headers .= "--$boundary\\r\
" .
"Content-Type: text/html; charset=ISO-8859-1\\r\
" .
"Content-Transfer-Encoding: base64\\r\
\\r\
";
$headers .= chunk_split(base64_encode($msg));
mail($to, "$subject", "", $headers);
if ($forward == 1) {
header ("Location:$location");
}
else {
echo "Thank you for submitting our form. We will get back to you as soon as possible.";
}
//echo($msg);
?>
This is the HTML
<form id="enquiry" name="enquiry" action="mailer.php" method="post" class="bodyform">
<fieldset>
<h2>Get in touch</h2>
<p>If you've got any questions or feedback, just drop us an email and we'll get back to you as soon as we can.</p>
<p>All fields are required</p>
<ol>
<li>
<label for="name">Your name:</label>
<input type="text" name="name" value="" id="name" class="required">
</li>
<li>
<label for="email">Your email:</label>
<input type="text" name="email" value="" id="email" class="required">
</li>
<li>
<label for="message">Your message:</label>
<textarea id="message" name="message" rows="8" cols="40" class="required"></textarea>
</li>
</ol>
<p class="submit">
<input type="submit" value="Submit »">
</p>
</fieldset>
</form>
Any help would be appreciated.
Thanks
Mike