PHP Mail Script Help

I’m using a script for a contact us page but the messages will not send unless a user inputs an email address from my domain. If they use Gmail, Yahoo, or any other email address from my domain it does not send. Any help would be greatly appreciated.

<?php /* Credits: Bit Repository URL: */ include dirname(dirname(__FILE__)).'/config.php'; error_reporting (E_ALL ^ E_NOTICE); $post = (!empty($_POST)) ? true : false; if($post) { include 'functions.php'; $name = stripslashes($_POST['name']); $email = trim($_POST['email']); $subject = stripslashes($_POST['subject']); $message = stripslashes($_POST['message']); $error = ''; // Check name if(!$name) { $error .= 'Please enter your name.
'; } // Check email if(!$email) { $error .= 'Please enter an e-mail address.
'; } if($email && !ValidateEmail($email)) { $error .= 'Please enter a valid e-mail address.
'; } // Check message (length) if(!$message || strlen($message) < 15) { $error .= "Please enter your message. It should have at least 15 characters.
"; } if(!$error) { ini_set("sendmail_from", WEBMASTER_EMAIL); // for windows server $mail = mail(WEBMASTER_EMAIL, $subject, $message, "From: ".$name." <".$email.">\r\n" ."Reply-To: ".$email."\r\n" ."X-Mailer: PHP/" . phpversion()); if($mail) { echo 'OK'; } } else { echo '
'; } } ?>

This script is faulty. The From address of an email message sent by your web site must be an address belonging to your site, not the address entered by the user. (They’re not actually the one sending the message, after all.)

Set the From address to a fixed value representing your web site, e.g.

$mail = mail(WEBMASTER_EMAIL, $subject, $message,
"From: " . WEBMASTER_EMAIL . “\r\n”
.“Reply-To: “.$email.”\r\n”
.“X-Mailer: PHP/” . phpversion());

Thanks for this. Quick and simple script and does the job.