simple email form problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jabbs72
Forum Newbie
Posts: 5
Joined: Sun Feb 15, 2009 5:42 am

simple email form problem

Post by jabbs72 »

Hi guys I am very new to PHP so please excuse my ignorance. I followed a tutorial on creating a simple enquiry form using php for my portfolio site and am having a slight problem.
The email is sent through without any problems to my inbox but all the information I have placed in the text fields (name,phone,email,comments) does not show at all, neither does the email address show in the from area (it just says unknown user). I have pasted the code below and would appreciate any help I can get. I have created the form in dreamweaver cs5 and have validated it using the validate form tool from within the software.

Cheers and happy festive season to all. :)

Code: Select all

<?php

/* Comment -- Subject and email variables */

	$emailSubject = 'Gavin Sinclair Enquiry !';
	$webMaster = 'enquiry@gavinsinclair.com.au';
	
	
/* Gathering data variables*/

	$nameField = $_POST['name'];
	$phoneField = $_POST['phone'];
	$emailField = $_POST['email'];
	$commentsField = $_POST['comments'];
	
	$body = <<<EOD
<br><hr><br>
name: $name <br>
phone: $phone <br>
email: $email <br>
comments: $comments <br>
EOD;

	$headers = "From: $email\r\n";
	$headers .= "Content-type: text/html\r\n";
	$success = mail($webMaster, $emailSubject, $body, $headers);
	
/* results render as html*/

	$theResults = <<<EOD
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Gavin Sinclair Graphic designer: Thank you</title>
<style type="text/css">
#thankyou_enquiry {
	font-family: "Arial Black", Gadget, sans-serif;
	font-size: 14px;
	color: #FFF;
	text-align: center;
	height: 110px;
	width: 500px;
	margin-right: auto;
	margin-left: auto;
}
</style>
<link href="css/screen.css" rel="stylesheet" type="text/css" />
</head>

<body bgcolor="#000000" text="#FFFFFF" link="#FFCC00" vlink="#FFCC00" alink="#FFCC00" topmargin="20">
<div id="thankyou_enquiry">
  <p>Thank you for your enquiry, I will be in contact with you shortly.</p>
  <p><a href="index.html">Back to Home Page</a></p>
</div>
</body>
</html>
EOD;
echo "$theResults";

?>
Last edited by califdon on Mon Dec 27, 2010 4:30 pm, edited 1 time in total.
Reason: Added syntax tags. (Please do likewise, in the future.)
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: simple email form problem

Post by califdon »

Change the variable names you use in the email body to match the names you assigned them right above that.
jabbs72
Forum Newbie
Posts: 5
Joined: Sun Feb 15, 2009 5:42 am

Re: simple email form problem

Post by jabbs72 »

Thanks for your reply Califdon i certainly appreciate it,

If you mean change the name in the form i have created to match the varialbles in the code they already match, if that is what you mean if not can you please explain further, again excuse my ignorance
jabbs72
Forum Newbie
Posts: 5
Joined: Sun Feb 15, 2009 5:42 am

Re: simple email form problem

Post by jabbs72 »

Thank you Califdon,

I worked out what you were describing and made the changes which worked perfectly, again thank you so much for your time.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: simple email form problem

Post by califdon »

jabbs72 wrote:Thanks for your reply Califdon i certainly appreciate it,

If you mean change the name in the form i have created to match the varialbles in the code they already match, if that is what you mean if not can you please explain further, again excuse my ignorance
No, look at your code. You assign the values you received from the form to 4 variables:

Code: Select all

   $nameField = $_POST['name'];
   $phoneField = $_POST['phone'];
   $emailField = $_POST['email'];
   $commentsField = $_POST;['comments']
But when you want to use those values in the email, you are using different names, so of course, the code has no clue as to what values you want to use:

Code: Select all

   <br><hr><br>
   name: $name <br>
   phone: $phone <br>
   email: $email <br>
   comments: $comments <br>
So you just have to match those. Either change $phoneField to $phone or change $phone to $phoneField, etc.
Post Reply