PHP form help - Results not appearing in email

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
shush1
Forum Newbie
Posts: 5
Joined: Fri Sep 29, 2006 6:16 am

PHP form help - Results not appearing in email

Post by shush1 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi I have set up a simple entry form, and I am submiting it using PHP to my email address, It works well when you fill the form in and send it, I receive the email however the email only displays the questions and not the answers that have been filled in on the form. Itss driving me crazy as top why this is not working. Can someone please help?

here is my form code, both form and PHP. Thanx

[syntax="html"]
<form
action='process.php' method="POST" name="survey" id="survey"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="19%"><p>First Name</p></td>
<td colspan="2" valign="top"><input name="q1" type="text" id="1" size="40" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td><div align="left">
<p>Family Name</p>
</div></td>
<td colspan="2" valign="top"><input name="q2" type="text" id="2" size="40" /></td>
</tr>
<tr>
<td><div align="left"></div></td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td valign="top"><div align="left">
<p>Address</p>
</div></td>
<td colspan="2" valign="top"><textarea name="q3" cols="40" rows="5" id="3"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td><div align="left">
<p>Email address</p>
</div></td>
<td colspan="2"><div align="left">
<input name="q4" type="text" id="4" size="40" />
</div></td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td><div align="left">
<p>Contact Tel. No</p>
</div></td>
<td colspan="2" valign="top"><input name="q5" type="text" id="5" size="40" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td valign="top"><div align="left"> Magazine (where you saw the competition) </div></td>
<td colspan="2" valign="top"><input name="q6" type="text" id="6" size="40" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td><div align="left"></div></td>
<td width="10%" valign="top"><div align="left">
<input type="submit" name="Submit" alt="Submit the survey!" value="Submit" />
</div></td>
<td width="71%" valign="top"><div align="left"><a href="http://www.persil.co.uk"><img src="logo.jpg" width="88" height="75" border="0" /></a></div></td>
</tr>
<tr>
<td><div align="left"></div></td>
<td colspan="2">&nbsp;</td>
</tr>
</table>
</form>
[/syntax]

Code: Select all

<?php

$result = "Winpersil.com competition entry\r\n\r\n";
$result .= "First Name: " . $q1 . "\r\n";
$result .= "Family Name: " . $q2 . "\r\n";
$result .= "Address: " . $q3 . "\r\n";
$result .= "Email address: " . $q4 . "\r\n";
$result .= "Contact Tel No.: " . $q5 . "\r\n";
$result .= "Magazine (where you saw the competition): " . $q6 . "\r\n";
if ($q4) {
$headers = "From: $name <$email>\r\n\r\n";
} else {
$headers = "From: No Name given <anonymous@yourserver.com>\r\n\r\n";
}

$sendit = mail("shushil@freshlemon.co.uk", "Winpersil.com competition entry", $result, $headers) or die("Something went wrong");

echo "<meta http-equiv='refresh' content='0; url=thank.htm'>";
die;

?>



thanx

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

Do you know about register_globals ? Or about $_POST array ?

That should be
$result .= "First Name: " . $_POST['q1'] . "\r\n";
shush1
Forum Newbie
Posts: 5
Joined: Fri Sep 29, 2006 6:16 am

Post by shush1 »

No sorry I don't so is what im using a old method that has now been discontinued?

So for my form to work I need to replace it with the script you gave me?

thanx
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

<?php
error_reporting(E_ALL);

$result = "Winpersil.com competition entry\r\n\r\n";
$result .= "First Name: " . $_POST['q1'] . "\r\n";
$result .= "Family Name: " . $_POST['q2'] . "\r\n";
$result .= "Address: " . $_POST['q3'] . "\r\n";
$result .= "Email address: " . $_POST['q4'] . "\r\n";
$result .= "Contact Tel No.: " . $_POST['q5'] . "\r\n";
$result .= "Magazine (where you saw the competition): " . $_POST['q6'] . "\r\n";
if ($_POST['q4']) {
	$headers = "From: $_POST[name] <$_POST[email]>\r\n\r\n";
} else {
	$headers = "From: No Name given <anonymous@yourserver.com>\r\n\r\n";
}

// $sendit = mail("shushil@freshlemon.co.uk", "Winpersil.com competition entry", $result, $headers) or die("Something went wrong");
echo '<div>', $headers, '</div><div>', $result, '</div>';
echo "<meta http-equiv='refresh' content='5; url=thank.htm'>";
die();
?>
and read http://de2.php.net/security.globals
shush1
Forum Newbie
Posts: 5
Joined: Fri Sep 29, 2006 6:16 am

Post by shush1 »

Hi thanx for that, you commented out my email address, thats where I want the results to be sent to, can that not be done?
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

You only should change your variable names from $q1 to $_POST['q1'] and so on the other variables.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

shush1 wrote:Hi thanx for that, you commented out my email address, thats where I want the results to be sent to, can that not be done?
That and the following echo is for debugging purposes only.
shush1
Forum Newbie
Posts: 5
Joined: Fri Sep 29, 2006 6:16 am

Post by shush1 »

Thanx a lot guys!
Post Reply