Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-10-2013, 04:38 AM   PM User | #1
sarahtoronto
New to the CF scene

 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
sarahtoronto is an unknown quantity at this point
Contact Form Sending With No Field Data

I have created a contact form for a client's website. The purpose of this form is for visitors to enter some information about themselves and once they press submit, my client receives the information via email. However, the form is being submitted without any information coming through. Just emails with no contents.

Why is the contents not being sent through? I would really appreciate some guidance!

Please see my code below:

Code:
<?php
/*
This first bit sets the email address that you want the form to be submitted to.
You will need to change this value to a valid email address that you can access.
*/
$webmaster_email = "me@email.com";

/*
This bit sets the URLs of the supporting pages.
If you change the names of any of the pages, you will need to change the values here.
*/
$feedback_page = "questionnaire1.html";
$error_page = "error_message.html";
$thankyou_page = "thank_you.html";

/*
This next bit loads the form field data into variables.
If you add a form field, you will need to add it here.
*/
$email_address = $_REQUEST['email_address'] ;
$name = $_REQUEST['name'] ;
$telephone = $_REQUEST['telephone'] ;
$brand = $_REQUEST['brand'] ;
$target_demo = $_REQUEST['target_demo'] ;
$describe_product = $_REQUEST['describe_product'] ;

/*
The following function checks for email injection.
Specifically, it checks for carriage returns - typically used by spammers to inject a CC list.
*/
function isInjected($str) {
	$injections = array('(\n+)',
	'(\r+)',
	'(\t+)',
	'(%0A+)',
	'(%0D+)',
	'(%08+)',
	'(%09+)'
	);
	$inject = join('|', $injections);
	$inject = "/$inject/i";
	if(preg_match($inject,$str)) {
		return true;
	}
	else {
		return false;
	}
}

// If the user tries to access this script directly, redirect them to the feedback form,
if (!isset($_REQUEST['email_address'])) {
header( "Location: $feedback_page" );
}

// If the form fields are empty, redirect to the error page.
elseif (empty($email_address) || empty($target_demo) || empty($describe_product) || empty($telephone) || empty($brand) || empty($name)) {
header( "Location: $error_page" );
}

// If email injection is detected, redirect to the error page.
elseif ( isInjected($email_address) ) {
header( "Location: $error_page" );
}


// If we passed all previous tests, send the email then redirect to the thank you page.
else {
mail( "me@email.com", "Client Questionnaire",
  "From: $email_address" );


header( "Location: $thankyou_page" );
}
?>
sarahtoronto is offline   Reply With Quote
Old 01-10-2013, 05:16 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,395
Thanks: 18
Thanked 351 Times in 350 Posts
sunfighter is on a distinguished road
Instead of reinventing the wheel maybe an existing code will do the job for you?
http://www.freecontactform.com/email_form.php
sunfighter is offline   Reply With Quote
Reply

Bookmarks

Tags
contact form, html

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:11 AM.


Advertisement
Log in to turn off these ads.