Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Why don't variables show up in my PHP email forms?

Why don't variables show up in my PHP email forms?
Thread Tools
Mac Elite
Join Date: Sep 2000
Location: New York
Status: Offline
Reply With Quote
May 13, 2003, 02:24 AM
 
I am trying to do use number of PHP email forms and in each one none of my variables (the form elements) show up in the messages. I turned on sendmail using the directions at http://www.macdevcenter.com/lpt/a/2692 and it now sends mail (which is definite progress) but it won't send variables in the email messages. This is a simple form I am using that I found online (I filled out my email address). When it sends all it sends it the email contents without any of the variables.

php page:
<?

//Declare the variables
$recipient = "myemailaddress@email.com";
$subject = "User Feedback";
$message = "Hi there! The user $name just filled in the contact for. The return email is $email and they said $comments";
$subject=$_POST['subject'];

//Contents of form
$name=$_POST['name'];
$email=$_POST['email'];
$comments=$_POST['comments'];

//mail() function sends the mail
mail($recipient,$subject,$message,$email);

//This line sends to thankyou page when finished
header("Location: http://resma.net/php/contact/sent.php");
?>


html page:
<html>
<head>
<title>Form</title>
</head>
<body>
<form action=form.php method=post>
<br>
Your Name: <input type=text name=name>
<br>
E-mail: <input type=text name=email>
<br>
Subject: <input type=text name=subject>
Comments<br>
<textarea name=comments></textarea>
<br>
<input type=submit value=Submit>



</body>
</html>

I have this problem with all form emailers that I have tried, including one generated from inPHormer, a cool program I found on versiontracker to generate PHP email forms (you have to go to the site to download the free version).

Does anyone know what's wrong? This is really frustrating me. Thanks.

EDIT: how do i get code to display properly in vBulletin? the code] tag made safari actually interpret and render the code.
     
Professional Poster
Join Date: Dec 2001
Location: somewhere
Status: Offline
Reply With Quote
May 13, 2003, 06:34 AM
 
//Contents of form
$name=$_POST['name'];
$email=$_POST['email'];
$comments=$_POST['comments'];

//Declare the variables
$recipient = "myemailaddress@email.com";
$subject = "User Feedback";
$message = "Hi there! The user $name just filled in the contact for. The return email is $email and they said $comments";
$subject=$_POST['subject'];


You have it backwards. You need to switch the section commented '//Contents of form' to be before the section commented '//Declare the variables'. What you are doing is using the variables $name, $email, and $comments before you read values into them from the form.
     
   
Thread Tools
Forum Links
Forum 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
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:32 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2