Contact form not working

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!

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");
?>
 
Thanks for the info! I just removed the eregi part in total and that still didn't work. Any suggestions on how to fix? (I'm a php newby..)
 
Put these two lines at the start of your script:
Code:
error_reporting(E_ALL);
display_errors = on;
then read what is displayed.
 
Thanks for the help! The result is a completely blanc page..
 
Was the blank page with the error checking?

I've been trying to avoid saying the following, but it might be your best bet rather than trying to fix what you have:
It may be worth you looking at using PHPMailer (there are some youtube videos which may help) or SwiftMailer. And it wouldn't hurt to re-write your form handle your code is not very secure.
 
The page was blank with error checking yes.

Thanks for the suggestions! I'll have a look at them!
 
Back
Top