Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variables not being sent to email 2

Status
Not open for further replies.

keepingbusy

Programmer
Apr 9, 2000
1,470
0
0
GB

Hi

Can someone give me any idea why variables from an enquiry form that match those in the below code are not being received in an email:

Code:
<?php 

$to='ouremail@someemailaddress.com';
$subject='Online Enquiry Received';

$name=$_POST['Name'];
$email=$_POST['Email'];
$phone=$_POST['Phone'];

$message="Name:  ". $name . "\r\n" . "Email:  " . $email . "\r\n" . "Phone:  " . $phone;

mail($to,$subject,$message);

?>

As mentioned we get the email with just the Name: Email: etc but the variables $name $ email etc are not being shown.

Any advice would be appreciated.

Thank you
 
The html form the $_POST variabe should come frome is actually doing a POST request (not GET)? And it has input elements with the names 'Name', 'Email' and 'Phone'? And you do validate them, so the user has to enter something before submitting?

Bye, Olaf.
 
Show us the relevant HTML.

As a debugging measure, try outputting the $_POST variable to make sure it actually has something in there.

A well placed conditional would also tell you if your variables are empty before sending the email.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]

<head>
<meta content="en-gb" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 2</title>
<style type="text/css">
.auto-style1 {
	text-align: center;
}
.auto-style2 {
	text-align: right;
}
.auto-style3 {
	text-align: left;
}
.auto-style4 {
	font-family: Calibri;
	font-size: small;
}
.auto-style7 {
	font-family: Arial;
}
.auto-style8 {
	text-align: center;
	font-family: Arial;
}
.auto-style10 {
	font-family: Arial;
	font-size: medium;
}
</style>
</head>

<body>
<form method="post" action="send.php">
	<div class="auto-style1">
		<table align="center" cellpadding="4" cellspacing="0" class="auto-style4" style="width: 840px">
			<tr>
				<td class="auto-style10" colspan="2"><strong>Enquiry Form</strong></td>
			</tr>
			<tr class="auto-style7">
				<td class="auto-style2" style="width: 420px">Name:</td>
				<td class="auto-style3" style="width: 420px">
				<input name="name" style="width: 300px" type="text" /></td>
			</tr>
			<tr class="auto-style7">
				<td class="auto-style2" style="height: 24px; width: 420px">
				Email:</td>
				<td class="auto-style3" style="height: 24px; width: 420px">
				<input name="email" style="width: 300px" type="text" /></td>
			</tr>
			<tr class="auto-style7">
				<td class="auto-style2" style="width: 420px">Phone:</td>
				<td class="auto-style3" style="width: 420px">
				<input name="phone" style="width: 300px" type="text" /></td>
			</tr>
			<tr>
				<td class="auto-style8" colspan="2" style="height: 24px">
				&nbsp;</td>
			</tr>
			<tr>
				<td class="auto-style2" style="width: 420px">&nbsp;</td>
				<td class="auto-style3" style="width: 420px">&nbsp;</td>
			</tr>
			<tr class="auto-style7">
				<td class="auto-style2" style="width: 420px">
				<input name="Submit1" type="submit" value="Send Enquiry" /></td>
				<td class="auto-style3" style="width: 420px">
				<input name="Reset1" type="reset" value="Clear Form" /></td>
			</tr>
		</table>
		<br />
	</div>
</form>
</body>

</html>

And the send.php file

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<style type="text/css">
.auto-style1 {
	text-align: center;
}
.auto-style2 {
	font-family: Arial;
	font-size: small;
}
.auto-style3 {
	color: #000000;
}
</style>
</head>

<body>
<div class="auto-style1">
<?php 

$to='ouremail@ouremail.com';
$subject='Online Enquiry Received';

$name=$_POST['Name'];
$email=$_POST['Email'];
$phone=$_POST['Phone'];

$message="Name:  ". $name . "\r\n" . "Email:  " . $email . "\r\n" . "Phone:  " . $phone;

mail($to,$subject,$message);

?>
 
<br />
	<span class="auto-style2">
<a href="ourpage.html"><span class="auto-style3">Back to or Home Page</span></a></span></div>

</body>

</html>

Thank you
 
PHP is case sensitive your html form has input nyme="name" and so you will have $_POST['name'] but not $_POST['Name']

print_r($_POST);

and you'll see what post elements are coming in.

Bye, Olaf.
 

Ok I'll revisit this tomorrow, off home now but thanks for your posts so far guys, I appreciate it.
 

Right, I've discovered the concept now and understand what you mean. The variables have to be exact e.g. name has to be name and Name or email as email not Email.

Just tried the form with a couple of fields and it works!

Thanks for your advice (and inspiration guys)

 

Just a quick question on this subject:

The code we are using for the send.php file which now transfers the variables is:

Code:
<?php 

$to='ourmail@someone.com';
$subject='Online Enquiry Received';

$title=$_POST['title'];
$forename=$_POST['forename'];
$surname=$_POST['surname'];
$email=$_POST['email'];
$address=$_POST['address'];
$telephone=$_POST['telephone'];
$othertelephone=$_POST['othertelephone'];
$bestway=$_POST['bestway'];
$howhelp=$_POST['howhelp'];
$foundout=$_POST['foundout'];


$message="Title:  ".$title. "\r\n" . "Forename:  " .$forename. "\r\n" . "Surname:  " .$surname. "\r\n" . "Email:  " .$email. "\r\n" . "Address:  " .$address. "\r\n" . "Telephone:  " .$telephone. "\r\n" . "Other Telephone:  " .$othertelephone. "\r\n" . "Best Way To Contact:  " .$bestway. "\r\n" . "How help:  " .$howhelp. "\r\n" . "Found Out:  " .$foundout. "\r\n"  ;


mail($to,$subject,$message);

?>

Slight problem in that the results appears on the email like this:

Title: Mr
Forename: John
Surname: Smith
Email: myemail@somehost.com
Address: 24 The High Street
Somearea
Ourtown
UK
Telephone: 012 3456 7890
Other Telephone: 087 3156 5432
Best Way To Contact: Email Only
How help: This is a test how may we help you Found Out: Internet Search Engine

As you can see the How help: Found Out: are on the same line.

Why is this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top