A
Anonymous
Guest
Hi all,
I used to have a working contact form but all of a sudden it's not working anymore. Been looking everywhere for an answer but don't see what's going wrong. I keep getting an error message when submitting a message: "Error: Invalid E-Mail Address". When I remove all error and security checks it works but there's no subject or message in the mail. Anyone know what might be causing the errors? PHP runs on 7.1.
Thanks a lot for your help!
I used to have a working contact form but all of a sudden it's not working anymore. Been looking everywhere for an answer but don't see what's going wrong. I keep getting an error message when submitting a message: "Error: Invalid E-Mail Address". When I remove all error and security checks it works but there's no subject or message in the mail. Anyone know what might be causing the errors? PHP runs on 7.1.
Thanks a lot for your help!
Code:
<?php
// VALUES FROM THE FORM
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['msg'];
// ERROR & SECURITY CHECKS
if ( ( !$email ) ||
( strlen($_POST['email']) > 200 ) ||
( !preg_match("#^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$#", $email) )
)
{
print "Error: Invalid E-Mail Address";
exit;
}
if ( ( !$name ) ||
( strlen($name) > 100 ) ||
( preg_match("/[:=@\<\>]/", $name) )
)
{
print "Error: Invalid Name";
exit;
}
if ( preg_match("#cc:#i", $message, $matches) )
{
print "Error: Found Invalid Header Field";
exit;
}
if ( !$message )
{
print "Error: No Message";
exit;
}
if (eregi("\r",$email) || eregi("\n",$email)){
print "Error: Invalid E-Mail Address";
exit;
}
if (FALSE) {
print "Error: You cannot send to an email address on the same domain.";
exit;
}
// CREATE THE EMAIL
$headers = "Content-Type: text/plain; charset=iso-8859-1\n";
$headers .= "From: $name <$email>\n";
$recipient = "MYEMAIL";
$subject = "MYMAILHEADER";
$message = wordwrap($message, 1024);
// SEND THE EMAIL TO YOU
mail($recipient, $subject, $message, $headers);
// REDIRECT TO THE THANKS PAGE
header("location: MYWEBSITETHANKS");
?>