PDA

View Full Version : PHP Contact Form Stopped Working - Help Please!


Ryan
08-22-2007, 05:47 AM
Hello all,

My website is laapa.com. I'm over on server curry and just within the last 15 hours or so, my script for my contact forms has stopped functioning correctly.

Now I just get blank emails with the template only and none of the inputted data!

A demo of the form I know works (or did work through yesterday afternoon) is http://www.laapa.com/htmlform.html. IF you try it, you should see on the confirmation page that no data is transferred or recorded.

Here is the PHP code I'm using which I purchased from www.phpcontactform.com since I'm not much of a programmer myself:


<?PHP
global $_POST;
$firstname = $_POST["firstname"] ;
$lastname = $_POST["lastname"];
$emailaddress = $_POST["emailaddress"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];
$phonenumber = $_POST["phonenumber"];
$where = $_POST["where"];
$message = $_POST["message"];

$to = "INSERTEMAILHERE(YES I DID THAT)";
$subject = "PHP Contact Form Submission";
$headers = "From: $emailaddress\n" . "MIME-Version: 1.0\n" .
"Content-type: text/html; charset=iso-8859-1";

$emailmessage = "<table width='300' border='0' align='left' cellpadding='0' cellspacing='0'>
<tr>
<td>
<div align='center'>
<table width='300' border='0' cellpadding='3' cellspacing='2' bgcolor='6A8494'>
<tr bgcolor='#FFFFFF'>
<td colspan='2'><font color='#333333'><strong><font size='2' face='Arial, Helvetica, sans-serif'><img src='../images/bullet2.jpg' width='16' height='16'>
Submitted Contact Form Information</font></strong></font></td>
</tr>
<tr bgcolor='#FFFFFF'>
<td width='95'><font color='#333333'><strong><font color='4C9C23' size='2' face='Arial, Helvetica, sans-serif'>First
Name</font></strong></font></td>
<td width='187'><font color='#333333'><font size='2' face='Arial, Helvetica, sans-serif'>$firstname</font></font></td>
</tr>
<tr bgcolor='#FFFFFF'>
<td><font color='#333333'><strong><font color='4C9C23' size='2' face='Arial, Helvetica, sans-serif'>Last
Name</font></strong></font></td>
<td><font color='#333333'><font size='2' face='Arial, Helvetica, sans-serif'>$lastname</font></font></td>
</tr>
<tr bgcolor='#FFFFFF'>
<td><font color='#333333'><strong><font color='4C9C23' size='2' face='Arial, Helvetica, sans-serif'>Email
Address</font></strong></font></td>
<td><font color='#333333'><font size='2' face='Arial, Helvetica, sans-serif'>$emailaddress</font></font></td>
</tr>
<tr bgcolor='#FFFFFF'>
<td><font color='#333333'><strong><font color='4C9C23' size='2' face='Arial, Helvetica, sans-serif'>City</font></strong></font></td>
<td><font color='#333333'><font size='2' face='Arial, Helvetica, sans-serif'>$city</font></font></td>
</tr>
<tr bgcolor='#FFFFFF'>
<td><font color='#333333'><strong><font color='4C9C23' size='2' face='Arial, Helvetica, sans-serif'>State</font></strong></font></td>
<td><font color='#333333'><font size='2' face='Arial, Helvetica, sans-serif'>$state</font></font></td>
</tr>
<tr bgcolor='#FFFFFF'>
<td><font color='#333333'><strong><font color='4C9C23' size='2' face='Arial, Helvetica, sans-serif'>Zip</font></strong></font></td>
<td><font color='#333333'><font size='2' face='Arial, Helvetica, sans-serif'>$zip</font></font></td>
</tr>
<tr bgcolor='#FFFFFF'>
<td><font color='#333333'><strong><font color='4C9C23' size='2' face='Arial, Helvetica, sans-serif'>Phone
Number</font></strong></font></td>
<td><font color='#333333'><font size='2' face='Arial, Helvetica, sans-serif'>$phonenumber</font></font></td>
</tr>
<tr bgcolor='#FFFFFF'>
<td><font color='#333333'><strong><font color='4C9C23' size='2' face='Arial, Helvetica, sans-serif'>Referred
By</font></strong></font></td>
<td><font color='#333333'><font size='2' face='Arial, Helvetica, sans-serif'>$where</font></font></td>
</tr>
<tr bgcolor='#FFFFFF'>
<td><font color='#333333'><strong><font color='4C9C23' size='2' face='Arial, Helvetica, sans-serif'>Message:</font></strong></font></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor='#FFFFFF'>
<td colspan='2'><font color='#333333' size='2' face='Arial, Helvetica, sans-serif'>$message</font></td>
</tr>
<tr bgcolor='#FFFFFF'>
<td colspan='2'><div align='center'><font color='#333333' size='2' face='Arial, Helvetica, sans-serif'><strong>Thank
You For Your Submission</strong></font></div></td>
</tr>
</table>
</div></td>
</tr>
</table>";

if (preg_match(' /[\r\n,;\'"]/ ', $_POST['emailaddress'])) {
exit('Invalid Email Address');
}
else {
mail($to,$subject,$emailmessage,$headers);
}


?>
<html>
<head>
<title>Contact Form Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="300" border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td>
<div align="center">
<table width="300" border="0" cellpadding="3" cellspacing="2" bgcolor="6A8494">
<tr bgcolor="#FFFFFF">
<td colspan="2"><font color="#333333"><strong><font size="2" face="Arial, Helvetica, sans-serif"><img src="http://www.phpcontactform.com/images/bullet2.jpg" width="16" height="16">
Submitted Contact Form Information</font></strong></font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="95"><font color="#333333"><strong><font color="4C9C23" size="2" face="Arial, Helvetica, sans-serif">First
Name</font></strong></font></td>
<td width="187"><font color="#333333"><font size="2" face="Arial, Helvetica, sans-serif"><?PHP echo $firstname ?></font></font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td><font color="#333333"><strong><font color="4C9C23" size="2" face="Arial, Helvetica, sans-serif">Last
Name</font></strong></font></td>
<td><font color="#333333"><font size="2" face="Arial, Helvetica, sans-serif"><?PHP echo $lastname ?></font></font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td><font color="#333333"><strong><font color="4C9C23" size="2" face="Arial, Helvetica, sans-serif">Email
Address</font></strong></font></td>
<td><font color="#333333"><font size="2" face="Arial, Helvetica, sans-serif"><?PHP echo $emailaddress ?></font></font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td><font color="#333333"><strong><font color="4C9C23" size="2" face="Arial, Helvetica, sans-serif">City</font></strong></font></td>
<td><font color="#333333"><font size="2" face="Arial, Helvetica, sans-serif"><?PHP echo $city ?></font></font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td><font color="#333333"><strong><font color="4C9C23" size="2" face="Arial, Helvetica, sans-serif">State</font></strong></font></td>
<td><font color="#333333"><font size="2" face="Arial, Helvetica, sans-serif"><?PHP echo $state ?></font></font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td><font color="#333333"><strong><font color="4C9C23" size="2" face="Arial, Helvetica, sans-serif">Zip</font></strong></font></td>
<td><font color="#333333"><font size="2" face="Arial, Helvetica, sans-serif"><?PHP echo $zip ?></font></font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td><font color="#333333"><strong><font color="4C9C23" size="2" face="Arial, Helvetica, sans-serif">Phone
Number</font></strong></font></td>
<td><font color="#333333"><font size="2" face="Arial, Helvetica, sans-serif"><?PHP echo $phonenumber ?></font></font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td><font color="#333333"><strong><font color="4C9C23" size="2" face="Arial, Helvetica, sans-serif">Referred
By</font></strong></font></td>
<td><font color="#333333"><font size="2" face="Arial, Helvetica, sans-serif"><?PHP echo $where ?></font></font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td><font color="#333333"><strong><font color="4C9C23" size="2" face="Arial, Helvetica, sans-serif">Message:</font></strong></font></td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="2"><font color="#333333" size="2" face="Arial, Helvetica, sans-serif"><?PHP echo $message ?></font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="2"><div align="center"><font color="#333333" size="2" face="Arial, Helvetica, sans-serif"><strong>Thank
You For Your Submission</strong></font></div></td>
</tr>
</table>

</div></td>
</tr>
</table>
</body>
</html>


If anyone has any ideas as to why this code isn't working, that'd be great and appreciated. Thanks!

dougp
08-22-2007, 08:57 AM
(See attachment on last post and changes)

Ryan
08-22-2007, 09:55 AM
Hi Doug,

That seems to have done the trick!

Regarding the original script I think it's supposed to work because Cirtex Level 3 support actually said:

"There appears some problem with the post method in the server and we are working on it."

I guess that doesn't affect this script though.

Now, I just need to update my regular forms. Can you let me know exactly what you changed so I don't miss anything in the transfers?

Thanks again!

dougp
08-22-2007, 10:48 AM
Yep, POST seems to be "borked" currently, annoying it is. But GET can work just as well in this case. The code changes I made will work for both POST and GET (so if POST gets repaired it will work if you change method back to POST) But you won't need to, it will work just fine as is with the changes regardless of the POST status.

Added (workaround when Globals are disabled ($global $var;))

if (!ini_get('register_globals')) {
while (list($key, $val) = @each($_GET)) $GLOBALS[$key] = $val;
while (list($key, $val) = @each($_POST)) $GLOBALS[$key] = $val;
while (list($key, $val) = @each($_COOKIE)) $GLOBALS[$key] = $val;
while (list($key, $val) = @each($_FILES)) $GLOBALS[$key] = $val;
while (list($key, $val) = @each($_SESSION)) $GLOBALS[$key] = $val;
}

Changed

global $_POST;
$firstname = $_POST["firstname"] ;
$lastname = $_POST["lastname"];
$emailaddress = $_POST["emailaddress"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];
$phonenumber = $_POST["phonenumber"];
$where = $_POST["where"];
$message = $_POST["message"];

TO

if ($_POST['emailaddress'] != "") {
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$emailaddress = $_POST["emailaddress"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];
$phonenumber = $_POST["phonenumber"];
$where = $_POST["where"];
$message = $_POST["message"];
} elseif ($_GET['emailaddress'] != "") {
$firstname = $_GET["firstname"];
$lastname = $_GET["lastname"];
$emailaddress = $_GET["emailaddress"];
$city = $_GET["city"];
$state = $_GET["state"];
$zip = $_GET["zip"];
$phonenumber = $_GET["phonenumber"];
$where = $_GET["where"];
$message = $_GET["message"];
}

Added (Better email check)

if (!function_exists('checkdnsrr')) {
function checkdnsrr($host, $type = '') {
if (!empty($host)) {
if ($type == '') $type = "MX";
@exec("nslookup -type=$type $host", $output);
while(list($k, $line) = each($output)) {
if (eregi("^$host", $line)) {
return true;
}
}
return false;
}
}
}

function checkemail($email) {
if ((preg_match('/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/', $email)) || (preg_match('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/',$email))) {
$host = explode('@', $email);
if(checkdnsrr($host[1].'.', 'MX')) return true;
if(checkdnsrr($host[1].'.', 'A')) return true;
if(checkdnsrr($host[1].'.', 'CNAME')) return true;
}
return false;
}

Changed

if (preg_match(' /[\r\n,;\'"]/ ', $_POST['emailaddress'])) {
exit('Invalid Email Address');

TO

if (!checkemail($emailaddress)) {
echo "Detected an invalid email address used. Please enter a valid email and try again.";
exit();


Also on the form itself change the method to GET instead of Post and see if that helps at all.

<form method="GET"


See updated attachment that includes all code with changes made to it.

Ryan
08-22-2007, 03:57 PM
Doug,

Thanks again...that's a great way to cover both ends when something breaks! I will implement that.

Thanks again for your help.

dougp
08-22-2007, 03:59 PM
Doug,

Thanks again...that's a great way to cover both ends when something breaks! I will implement that.

Thanks again for your help.
yep, no prob m8, glad its working for you.