email header not sending...

I have a form on this page: http://www.webauthorsgroup.com/contacform/contact.html which I added a “website” field, but it doesn’t come through my email. All the other fields do though. Can someone please have a look and let me know what I need to do?

My php config page is as follows:

[embed=425,349]<?php
if($_POST)
{
$to_Email = "[email protected]"; //Replace with recipient email address
$subject = ‘WebAuthorsGroup Form’; //Subject line for emails

//check if its an ajax request, exit if not
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {

	//exit script outputting json data
	$output = json_encode(
	array(
		'type'=>'error', 
		'text' => 'Request must come from Ajax'
	));
	
	die($output);
} 

//check $_POST vars are set, exit if any missing
if(!isset($_POST["userName"]) || !isset($_POST["userEmail"]) || !isset($_POST["userPhone"]) || !isset($_POST["userMessage"]))
{
	$output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!'));
	die($output);
}

//Sanitize input data using PHP filter_var().
$user_Name        = filter_var($_POST["userName"], FILTER_SANITIZE_STRING);
$user_Email       = filter_var($_POST["userEmail"], FILTER_SANITIZE_EMAIL);
$user_Phone       = filter_var($_POST["userPhone"], FILTER_SANITIZE_STRING);
$user_Message     = filter_var($_POST["userMessage"], FILTER_SANITIZE_STRING);

//additional php validation
if(strlen($user_Name)<4) // If length is less than 4 it will throw an HTTP error.
{
	$output = json_encode(array('type'=>'error', 'text' => 'Name is too short or empty!'));
	die($output);
}
if(!filter_var($user_Email, FILTER_VALIDATE_EMAIL)) //email validation
{
	$output = json_encode(array('type'=>'error', 'text' => 'Please enter a valid email!'));
	die($output);
}
if(!is_numeric($user_Phone)) //check entered data is numbers
{
	$output = json_encode(array('type'=>'error', 'text' => 'Only numbers allowed in phone field'));
	die($output);
}
if(strlen($user_Message)<5) //check emtpy message
{
	$output = json_encode(array('type'=>'error', 'text' => 'Too short message! Please enter something.'));
	die($output);
}

//proceed with PHP email.
$headers = 'From: '.$user_Email.'' . "\r\n" .
'Reply-To: '.$user_Email.'' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

$sentMail = @mail($to_Email, $subject, $user_Message, $user_Website .'  -'.$user_Name, $headers);

if(!$sentMail)
{
	$output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.'));
	die($output);
}else{
	$output = json_encode(array('type'=>'message', 'text' => 'Thank you '.$user_Name .'. We will be in contact with you.'));
	die($output);
}

}
?>[/embed]

Well, I am a little confused. You have no code in this page for your new field.
We can not help you fix it if it is not there.

Are you asking for code to add that new filed to your system?
You added the website to the function mail(); But, that is not a good item to include
as a header. Not even sure what you are attempting to do.

So, here is what I think. You have a user enter a website’s URL. This is usually in the form of
HTTP://www.somesite.com or just www.somesite.com . Now, you retrieve this value using
the standard PHP line like: $user_website = $_POST[“user_website”]; Then, the variable
($user_website) is cleaned up to make sure that nothing bad gets in.

Once you have the website, you save it to your database for future use or email it as part of the
message. It is not a header to be sent in the mail() function. You could use it inside a message
by adding it to the text. Something like:
$user_message .= “\r\nUser Website=” . $user_website . “\r\n”; Or however you want it to be.

So, what are you trying to do? In your current code, you load all of the variables thru the $_POST[]
commands EXCEPT the website input field. Is that what you need help with?

I think I’ve got it figured out from the info you provided - thanks!

Cool ! Good for you. I will mark this thread solved…

Sponsor our Newsletter | Privacy Policy | Terms of Service