Page 1 of 1

Simple php form that doesnt want to work!

Posted: Wed Oct 04, 2006 6:20 am
by dankingsley
JayBird | 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 been trying to set up a simple form for a little while now. It is basically to allow people to tell a friend about a website. There is an error every time i try, can someone please let me know what I have done wrong!

The form code is:

Code: Select all

<p><img border="0" src="images/tell_a_friend.png" width="423" height="24"></p>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
  <tr>
    <td width="100%"><p>Pass the word on, tell other people about Spoken Groove!</p>
    <p>
          <form action="formtoemail_friend.php" method="post">
          <table border="0" cellspacing="5">
          <tr><td align="left"><p>Your Name:</p></td><td align="left">
          <input type="text" size="36" name="Name"></td></tr>
          <tr><td align="left"><p>Your Email address:</p></td><td align="left">
          <input type="text" size="36" name="Email"></td></tr>
          <tr><td align="left"><p>Friends Name:</p></td><td align="left">
          <input type="text" size="36" name="FName"></td></tr>
          <tr><td align="left"><p>Friends Email address:</p></td><td align="left">
          <input type="text" size="36" name="FEmail"></td></tr>
          <tr><td valign="top" align="left"><p>Message:</p></td><td align="left">
          <textarea name="Message" rows="6" cols="30"></textarea></td></tr>
          <tr><td align="left">&nbsp;</td><td align="left"><input type="submit" value="Send"></td></tr>
          </table>
          </form>
        
    </td>
  </tr>
  </table>

The code for formtoemail_friend.php is:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
<title>Spoken Groove</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Language" content="en-uk">
</head>

<body bgcolor="#ffffff" text="#000000">

<div>
<center>
<p><font face="arial" size="2"><a href="index.php?location=thanks_friend">Click here to continue</a></font></p>
</center>
</div>

</body>
</html>

<?php
$name=$_post['Name'];
$email=$_post['Email'];
$fname=$_post['FName'];
$femail=$_post['FEmail'];
$message=$_post['Message];

$msg="$name says: $message;
$subject = "Spoken Groove";
$headers = "From: $email \r\n";
$headers .= "Reply-To: $email \r\n";
$headers .= "Return-Path: $email \r\n";

mail($femail, $subject, $msg, $headers);

?>

JayBird | 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]

Posted: Wed Oct 04, 2006 6:31 am
by impulse()
What's the error?

Posted: Wed Oct 04, 2006 6:32 am
by impulse()

Code: Select all

$msg="$name says: $message;
Should be

Code: Select all

$msg="$name says: $message";


Posted: Wed Oct 04, 2006 6:33 am
by dankingsley
Sorry I forgot to post that!


Parse error: syntax error, unexpected $end in *********************/formtoemail_friend.php on line 36

Posted: Wed Oct 04, 2006 6:36 am
by impulse()
Which one's line 36? :D

I'm assuming it's the line with

Code: Select all

$msg="$name says: $message;
on it.

Posted: Wed Oct 04, 2006 6:40 am
by dankingsley
impulse() wrote:

Code: Select all

$msg="$name says: $message;
Should be

Code: Select all

$msg="$name says: $message";
Yeh well spotted! but it doesnt solve the problem, same error message (and i did clear my history!)

Posted: Wed Oct 04, 2006 6:41 am
by dankingsley
nope. 36 is the last line! it doesnt help at all!

Posted: Wed Oct 04, 2006 6:50 am
by JayBird
errors become obvious when you use sytnax highlighting ;)

Hint, there are 2 errors...1 mentions above and another one...a missing single quote (')

Posted: Wed Oct 04, 2006 7:03 am
by impulse()
I've found it. Just look for the place where the code starts bleeding :)

Posted: Wed Oct 04, 2006 9:04 am
by dankingsley
thanks :) think that should be sorted now!

Posted: Wed Oct 04, 2006 9:11 am
by dankingsley
actually! there is now no error, so it seems to be working, but if I test it out with a couple of my email address, no email is sent! Is there maybe something else which I have done wrong to stop it from working?

Here is the correct php at the moment:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 

<head> 
<title>Spoken Groove</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<meta http-equiv="Content-Language" content="en-uk"> 
</head> 

<body bgcolor="#ffffff" text="#000000"> 

<div> 
<center> 
<p><font face="arial" size="2"><a href="index.php?location=thanks_friend">Click here to continue</a></font></p> 
</center> 
</div> 

</body> 
</html> 

<?php 
$name=$_post['Name']; 
$email=$_post['Email']; 
$fname=$_post['FName']; 
$femail=$_post['FEmail']; 
$message=$_post['Message']; 

$msg="$name says: $message"; 
$subject = "Spoken Groove"; 
$headers = "From: $email \r\n"; 
$headers .= "Reply-To: $email \r\n"; 
$headers .= "Return-Path: $email \r\n"; 

mail($femail, $subject, $msg, $headers); 

?>

Posted: Wed Oct 04, 2006 9:12 am
by n00b Saibot
$femail shoud be $email on last line

Posted: Wed Oct 04, 2006 9:14 am
by dankingsley
n00b Saibot wrote:$femail shoud be $email on last line
are you sure? I dont think it should be, since that should be the email addy that the form is being sent to, and that is $femail.

Posted: Wed Oct 04, 2006 9:42 am
by n00b Saibot
sorry my bad.

the $_post should be $_POST.

Posted: Wed Oct 04, 2006 9:43 am
by dankingsley
ahhh! that shows my complete lack in php :) Works now though, thanks for that! I should really do a more secure form! but this will have to do for now i guess. Thanks