November 29, 201312 yr Hi Guys. Wondering if anyone can help. I've been trying to sort this out for the last 3 days and can't seem to get anywhere. I'm currently working on a php mail script with jquery & php validation. The page woks well and sends the users contact details to the server, but refuses to display anything in the (From:) (see attached) so wont forward it to the virgin media email. The script I have is: <?php //If the form is submitted if(isset($_POST['submit'])) { //Check to make sure that the name field is not empty if(trim($_POST['contactname']) == '') { $hasError = true; } else { $name = trim($_POST['contactname']); } //Check to make sure that the name field is not empty if(trim($_POST['postcode']) == '') { $hasError = true; } else { $postcode = trim($_POST['postcode']); } //Check to make sure sure that a valid email address is submitted if(trim($_POST['number']) == '') { $hasError = true; } else { $number = trim($_POST['number']); } //Check to make sure that the subject field is not empty if(trim($_POST['postcode']) == '') { $hasError = true; } else { $postcode = trim($_POST['postcode']); } //Check to make sure sure that a valid email address is submitted if(trim($_POST['email']) == '') { $hasError = true; } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) { $hasError = true; } else { $email = trim($_POST['email']); } //Check to make sure comments were entered if(trim($_POST['message']) == '') { $hasError = true; } else { if(function_exists('stripslashes')) { $message = stripslashes(trim($_POST['message'])); } else { $message = trim($_POST['message']); } } //If there is no error, send the email if(!isset($hasError)) { $ $emailTo = 'contact@r-m-t.org.uk'; $body = "Name: $name \n\n Email: $email \n\n Contact No.: $number \n\nPost Code: $postcode \n\n Message:\n $message"; $headers = 'Website Contact Form'; mail($emailTo, $headers, $body ); $emailSent = true; } } ?> can anyone help or suggest a way to work round virgins spam filters to allow. Thanks
November 29, 201312 yr The mail function should be: mail($to, $subject, $message, $headers); In your case: mail($emailTo, $subject, $body, $headers); Rename $headers to $subject Your new $headers should be: $headers = 'From: whatever@whatever'; Edit: For example: if(!isset($hasError)) { $emailTo = 'contact@r-m-t.org.uk'; $body = "Name: $name \n\n Email: $email \n\n Contact No.: $number \n\nPost Code: $postcode \n\n Message:\n $message"; $subject = 'Website Contact Form'; $headers = 'From: whatever@whatever'; mail($emailTo, $subject, $body, $headers); $emailSent = true; } Check out http://php.net/manual/en/function.mail.php#example-3374 Edited November 29, 201312 yr by Gibbs
Create an account or sign in to comment