...

View Full Version : Mail Form Variables



pilotdude647
10-17-2012, 01:29 PM
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):

<?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:

<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):

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

sunfighter
10-17-2012, 05:23 PM
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.

pilotdude647
10-17-2012, 10:58 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum