My contact form was working fine before but my hosting upgraded to PHP ver 4.4.8 and now is not working. I am not good in PHP coding, I coudn't figure it out. Any of your help is appreciated. Thanks in advance. below is my code:
<?php
$to = "myemail@mysite.com";
$message = "Name: $Name\nEmail:$Email\nPhone:$Phone\nComments: $Comments\n ";
#go to html thank you... we will contact you...
$goto_after_mail= "www.mysite.com/contactsent.html";
#blank form submitted, ask to fill form again.....
$goto_err1="http://www.mysite.com/error1.html ";
#if valid email, ask to fill form again..
$goto_err2="http://www.mysite.com/error2.html ";
if (($Email == "") || ($Phone == "") || ($Name=="") || ($Comments==""))
{
header("Location: ".$goto_err1);
}
else
{
$eLog="/tmp/mailError.log";
Get the size of the error log
ensure it exists, create it if it doesn't
$fh= fopen($eLog, "a+");
fclose($fh);
$originalsize = filesize($eLog);
#-------------------------------------------------------------------------------------------
function emailsyntax_is_valid($Email)
{
$to_work_out = explode("@", $Email);
if (!isset($to_work_out[0])) return FALSE;
if (!isset($to_work_out[1])) return FALSE;
$pattern_local = '([0-9a-z]([-|]?[0-9a-z]+))(([-|]?).([-|]?)[0-9a-z]([-|]?[0-9a-z]+)+)([-|_]?)$';
$pattern_domain = '([0-9a-z]+([-]?[0-9a-z]+))(([-]?).([-]?)[0-9a-z]([-]?[0-9a-z]+)+)*.[a-z]{2,4}$';
$match_local = eregi($pattern_local, $to_work_out[0]);
$match_domain = eregi($pattern_domain, $to_work_out[1]);
if ($match_local && $match_domain) {
return TRUE;
}
return FALSE;
}
if (emailsyntax_is_valid($Email)) {
mail ($to, "subject contact", $message , "Cc:$Email");
header("Location: ".$goto_after_mail);
}
if (!emailsyntax_is_valid($Email)) {
header("Location: ".$goto_err2);
}
#------------------end check mail valid-------
# NOTE: PHP caches file status so we need to clear
# that cache so we can get the current file size
#/
clearstatcache();
$finalsize = filesize($eLog);
//Check if the error log was just updated
if ($originalsize != $finalsize)
{
print "<p>There was a problem sending the mail. Please try again later or send the message to<a href=\"$to\">$to</a> using your own mail client progam.</p>";
}
}
?>