I am a total newbie and I need help with this code. I uploaded the script and the form shows on my site. The problem is when I hit submit it gives me this error "Your email address contains errors. " I used different types of legit email addresses to test it out but I get the same error. I am not fluent in php talk so please explain in layman's term. Any help is appreciated. Thanks.
I think that maybe there is an error in the way the codes are written in the folowing lines, but I have included the entire script for review.
// Check email address for certain charcters
elseif (!eregi(".+@.+\..+$", $from))
{
$errorMes4="ERROR: Your email address contains errors. "; $error=1;
}
THIS IS THE ENTIRE CODE:
<?php
// Include webmaster settings file
include('../config.php');
// Below code may or may not be necessary for you
$name = $POST['name']; $from = $POST['from']; $message = $_POST['message'];
// Set IP variable based on registar globals status
$register_globals = (bool) ini_get('register_gobals');
if ($register_globals) { $ip=getenv(REMOTE_ADDR); }
else $ip=$_SERVER['REMOTE_ADDR'];
// If webmaster wants to do domain checks
if($verify_referrer=="1")
{
// If the domain referrer DOESN'T match either the set domain or domainAlias variable
if(!eregi("$domain", $HTTP_REFERER) && !eregi("$domainAlias", $HTTP_REFERER))
{
$error=1;
// If webmaster wants to log 3rd party domain attempts
if($ipLogging=="1"){
$date=date ("l dS of F Y h:i:s A");
$ipLog="ipLog.htm";
$fp=fopen("$ipLog", "a+");
fputs($fp, "<font face=arial size=3> >>> Logged IP address: $ip - Date: $date<br>");
fclose($fp);
$errorMesB="ERROR: Invalid domain.<br><br><b>NOTICE:</b> Your IP has been logged as: $ip."; $error=1;
}
else{ $errorMesA="ERROR: Invalid domain."; $error=1; }
// If webmaster wants to be notified via email of 3rd party domain attempts
if($notify=="1"){
$subject=$notifySubject;
// If webmaster wants mail sent in HTML format
if($HTMLmailFormat=="1"){
$body=" <font face=arial size=3><br>
--------<font color=red>WARNING!</font><font face=arial size=3> Form abuse notification ------
<br><br><br><font face=arial size=2>A person has attempted to abuse the contact form.
<br><font face=arial size=2>Their IP address was logged as: $ip <br></font><br>";
}
// If no HTML then send as plain text
else{
$body=" \n--------WARNING! Form abuse notification ------\n\n\n
A person has attempted to abuse the contact form.\n
Their IP address was logged as: $ip \n";
}
$from=$notifyFrom;
// Set headers based on content type (plain / HTML)
if($HTMLmailFormat=="1") $headers="Content-Type: text/html; charset=windows-1252 \n";
else $headers="Content-Type: text/plain \n";
$headers.="From: $from \n";
$headers.="X-mailer: \"contactMe\n";
// Mail notice to webmaster
mail($to,$subject,$body,$headers);
$errorMesC="An email with this information has been sent to the webmaster."; $error=1;
}
}
}
// Trim whitespace from user input and replace potentially harmfull charchters
$name=trim($name); $name = preg_replace("/>/","]",$name); $name = preg_replace("/</","[",$name);
// Trim whitespace from user input
$message=trim($message);
// If user enters NO name
if($name==""){ $errorMes1="ERROR: You didn't write your name. "; $error=1; }
elseif($message==""){ $errorMes2="ERROR: You didn't write a message. "; $error=1; }
// Determine the length of the message
elseif (strlen($message) >= $maxSize) { $errorMes3="ERROR: Your message is too long. The maximum characters allowed is $maxSize. "; $error=1; }
// If all is well so far there are no errors
else
$error=0;
// If there IS data in the email field then check it
if ($from!=""){ $errorMes5="ERROR: You need to enter an email address. "; $error=1; }
// Check email address for certain charcters
elseif (!eregi(".+@.+\..+$", $from))
{
$errorMes4="ERROR: Your email address contains errors. "; $error=1;
}
// If email address pass check then trim whitespace
else
$from=trim($from);
// If there has been an error then display the error
if ($error=="1"){
echo ("<title>SendMail Error</title>
<body><br>
<p style=\"font:11pt arial\">SendMail <font color=red> Error</font>
<br><br>The following errors have occured:<br><br>
$errorMes1<br>$errorMes2<br>$errorMes3<br>$errorMes4<br>$errorMes5<br>$errorMesA<br>$errorMesB<br>$errorMesC<br>
<br><a href=\"../contactMe.htm\" style=\"color:black\">Click here</a> to try again. </body></html>"); exit(0);
}
// If there has been no error then send mail
else if ($error=="0"){
// If webmaster wants mail sent in HTML format
if($HTMLmailFormat=="1") {
$message = preg_replace("/>/",">",$message); $message = preg_replace("/</","<",$message);
$body="<font face=arial size=2>$message</font <br><br><br>
<font face=\"ms sans serif\" size=2>
--------------- SENDER INFORMATION ------------
<br>This message was sent to you by $name.<br>
$name's email address is: $from<br>
$name's IP address is: $ip </font><br>";
}
// If webmaster wants mail sent in plain text format
else{
$body="$message\n\n\n
--------------- SENDER INFORMATION ------------
\nThis message was sent to you by $name.\n
$name's email address is: $from\n
$name's IP address is: $ip \n";
}
$from="\"$name\" <$from>";
// Set headers based on content type (plain / HTML)
if($HTMLmailFormat=="1") $headers="Content-Type: text/html; charset=windows-1252\n";
else $headers="Content-Type: text/plain \n";
$headers.="From: $from \n";
$headers.="X-mailer: \"contactMe\n";
// Send mail
mail($to,$subject,$body,$headers);
// display mail sent message
echo (" <title>SendMail Notice: mail was successfully sent</title><body><br><br><br><br>
<p style=\"font:11pt arial\" align=center>Your mail has been successfully sent...<i>Thank you</i></p>
</body></html>"); exit(0);
// exit script
} exit(0);
?>