I have an awesome form processor that a good friend of mine wrote that worked on my other host, but the strlen checks began to fail once I moved my sites here. I was hoping someone may be able to give me some ideas on how to resolve this.
Or tell me what to add to the bare script so I can strip html and prevent some spammers.
There are two hidden input fields in the form itself, one for redirect and one for recipient.
Here's the bare code which still works:
<?php
/**
* Form Processing Script
* Version 0.1a
* @DATE November 29, 2006
* @author Genesis Font
* @copyright 2006 prolinuxwebhosting.com
* Form must have the following hidden fields: recipient (should be the email address that will eceive the emailed message) and redirect (full url including http:// to the thankyou page)
*/
$datetime = date("l dS of F Y H:i:s");
$message = "On $datetime\n";
$message .= "<br />Here are the details of the form submission:\n";
while (list($key, $val) = each($_POST)) {
if ($key == 'redirect') {
$redirect = $val;
}
if ($key == 'recipient') {
$to = $val;
}
if (($key != 'redirect') and ($key != 'recipient')) {
$val = trim($val);
$message .= "<br />$key: $val\n";
}
//echo "$key: $val<br />";//debugging info
$lcval = strtolower($val);
$pos = strpos($lcval,"http://");
}
$ServerName = $_SERVER["HTTP_HOST"];
$message .= "<br /> Site: $ServerName \n";
$visitorip = $_SERVER['REMOTE_ADDR'] ;
$message .= "<br /> IP: $visitorip \n";
//Format Email
$email = $to;
$subject = "New Form Submission";
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
//Send Email
mail($to,$subject,$message,$headers);
//redirect
header("Location: $redirect");
?>
Here's the code with the strlen which doesn't work and gives an error about the header already being sent:
<?php
/**
* Form Processing Script
* Version 0.1a
* @DATE November 29, 2006
* @author Genesis Font
* @copyright 2006 prolinuxwebhosting.com
* Form must have the following hidden fields: recipient (should be the email address that will receive the emailed
message) and redirect (full url including http:// to the thankyou page)
*/
$datetime = date("l dS of F Y H:i:s");
$message = "On $datetime\n";
$message .= "<br />Here are the details of the form submission:\n";
while (list($key, $val) = each($_POST)) {
if ($key == 'redirect') {
$redirect = $val;
}
if ($key == 'recipient') {
$to = $val;
}
if (($key != 'redirect') and ($key != 'recipient')) {
$val = trim($val);
$message .= "<br />$key: $val\n";
}
}
echo "$key: $val<br />";//debugging info
$lcval = strtolower($val);
$pos = strpos($lcval,"http://");
//Genesis' code//
$ServerName = $_SERVER["HTTP_HOST"];
$message .= "<br /> Site: $ServerName \n";
$visitorip = $_SERVER['REMOTE_ADDR'] ;
$message .= "<br /> IP: $visitorip \n";
//new code
// Validation
if (strlen($first_name) <1)
{
header("Location: error.php");
exit;
}
if (strlen($first_name) >25)
{
header("Location: error.php");
exit;
}
if (strlen($last_name) <1)
{
header("Location: error.php");
exit;
}
if (strlen($last_name) >25)
{
header("Location: error.php");
exit;
}
if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $vis_email))
{
header("Location: error.php");
exit;
}
if (strlen($vis_email) == 0 )
{
header("Location: error.php");
exit;
}
//end new code
//Format Email
$email = $to;
$subject = "New Form Submission";
$headers = "From: $vis_email\r\n";
$headers .= "Content-type: text/html\r\n";
//Send Email
mail($to,$subject,$message,$headers);
//redirect
header("Location: $redirect");
?>
Thanks in advance!