Go Back   CodingForums.com > :: Server side development > PHP

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 10-17-2012, 12:29 PM   PM User | #1
pilotdude647
New to the CF scene

 
Join Date: Oct 2012
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
pilotdude647 is an unknown quantity at this point
Unhappy Mail Form Variables

Hi,

I am having great difficulty trying to get my php script to include the form data in a message. It sends the message but it is blank.

When i click submit, javascript will validate the form is entered (works) and then use a php script to email it (doen't work).

php code (separate .php file):
Code:
<?php 
$fname = $_POST["First Name"];
$email = $_POST["Email"];
$to = "xxxx@xxxx";
$subject = "Newsletter Subscription";
$message = "$fname $email";
$from = "xxxx@xxxx";
$headers = "From:" . $from;
mail ($to,$subject,$message,$headers); 
?>
HTML Code:
Code:
 <form action="sendnewsletterform.php" method="post" name="newsletter" enctype="text/plain" onsubmit="return validateFormNewsletter()">
        Your First Name: <input name="First Name" type="text" id="name" size="50" maxlength="60" /><font color="#FF0000">*</font><br />
        Your Email Address: <input name="Email" type="text" id="email" size="50" maxlength="60" /><font color="#FF0000">*</font><br />
        <input name="Newsletter Submit" type="submit" /><input name="Newsletter Reset" type="reset" /></form>
Javascript Code (separate .js file):
Code:
function validateFormNewsletter()
{
	var x=document.forms["newsletter"]["First Name"].value;
	if (x==null || x=="")
	{
		alert("First name must be entered");
		return false;
	}
	var x=document.forms["newsletter"]["Email"].value;
	var atpos=x.indexOf("@");
	if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
	{
		alert("Not a valid e-mail address");
		return false;
	}
}
If anyone can correct my code so that it works please do.

any help is greatly appreciated

Last edited by pilotdude647; 10-17-2012 at 12:30 PM.. Reason: spelling
pilotdude647 is offline   Reply With Quote
Old 10-17-2012, 04:23 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,365
Thanks: 18
Thanked 348 Times in 347 Posts
sunfighter is on a distinguished road
In the form tag this: enctype="text/plain" is killing you remove it.
Next name="First Name".
A space (see final scene in Body Snatchers 1978 Donald Sutherland). I have found out in my 50 years of working with computers that spaces are not your friends and not only leave when your in trouble but will stab you in the back and cause the trouble. This is a case for that. Use name="name" or name="First_Name" Change the php and javascript accordingly.
sunfighter is offline   Reply With Quote
Users who have thanked sunfighter for this post:
pilotdude647 (10-17-2012)
Old 10-17-2012, 09:58 PM   PM User | #3
pilotdude647
New to the CF scene

 
Join Date: Oct 2012
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
pilotdude647 is an unknown quantity at this point
Quote:
Originally Posted by sunfighter View Post
In the form tag this: enctype="text/plain" is killing you remove it.
Next name="First Name".
A space (see final scene in Body Snatchers 1978 Donald Sutherland). I have found out in my 50 years of working with computers that spaces are not your friends and not only leave when your in trouble but will stab you in the back and cause the trouble. This is a case for that. Use name="name" or name="First_Name" Change the php and javascript accordingly.
Thank you so much @sunfighter. It works perfectly now
pilotdude647 is offline   Reply With Quote
Reply

Bookmarks

Tags
form, mail, message, php, variable

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 03:06 AM.


Advertisement
Log in to turn off these ads.