Simple PHP Email Sending Form

dquigley

New Member
Messages
249
Reaction score
0
Points
0
So I am reading a PHP book that gives me lessons and teaches me how to code it and I am currently trying to create a simple form that lets you enter your name email and a message and then that sends it to the email address. The problem is when i click the submit form it just seems to refresh the page, the data I input disappears, and the page stays the same, and I checked my email and it wasn't sent. However the coding is supposed to redirect to a page saying your email was sent blah, anyways here is the code, please tell me the typo I made, I would like to keep the coding the same, as this is the way the book is teaching me, I am sure I just made a simple error.

Heres the HTML Form Page
<HTML>
<HEAD>
<TITLE>Simple Feedback Form</TITLE>
</HEAD>
<BODY>

<FORM METHOD="POST" ACTION="send_simpleform.php">

<P><strong>Your Name:</strong><br>
<INPUT type="text" NAME="sender_name" SIZE=30></P>

<P><strong>Your E-Mail Address:</strong><br>
<INPUT type="text" NAME="sender_name" SIZE=30></P>

<P><strong>Message:</strong><br>
<TEXTAREA NAME="message" COLS=30 ROWS=5 WRAP=virtual></TEXTAREA></P>

<P><INPUT TYPE="submit" NAME="submit" VALUE="Send This Form"></P>

</FORM>
</BODY>
</HTML>

And Here Is The PHP Part
PHP:
<?

if (($_POST[sender_name] == "") ||
    ($_POST[sender_email] == "") ||
    ($_POST[message] == "")) {
    header("Location: simple_form.html");
    exit;
}

$msg = "E-MAIL SENT FROM WWW SITE\n";
$msg .= "Sender's Name:\t$_POST[sender_name]\n";
$msg .= "Sender's E-Mail:\t$_POST[sender_email]\n";
$msg .= "Message:\t$_POST[message]\n";
$to = "dquigley@dollarstoriches.com";
$subject = "Web Site Feedback";
$mailheaders = "From: My Web Site <dquigley@dollarstoriches.com>\n";
$mailheaders .= "Reply-To: $_POST[sender_email]\n";
mail($to, $subject, $msg, $mailheaders);

?>

<HTML>
<HEAD>
<TITLE>Simple Feedback Form Sent</TITLE>
</HEAD>
<BODY>

<H1>The following e-mail has been sent:</H1>

<P><strong>Your Name:</strong><br>
<? echo "$_POST[sender_name]"; ?>
<P><strong>Your E-Mail Address:</strong><br>
<? echo "$_POST[sender_email]"; ?>
<P><strong>Message:</strong><br>
<? echo "$_POST[message]"; ?>

</BODY>
</HTML>
 

dquigley

New Member
Messages
249
Reaction score
0
Points
0
The <?PHP doesnt make a difference and I made a point of saying I dont want to redo the script I just want to find the error, so me copying your whole script wouldnt be me creating it. So thanks but I only need to find the error not redo my script.
 

tttony

Member
Messages
147
Reaction score
0
Points
16
Ok I just show the correct way, try with my code because I fixed the error.. just try and tell me...
 

dquigley

New Member
Messages
249
Reaction score
0
Points
0
ok well what was the error u fixed? just tell me what to fix, I dont want to just copy and paste that wont help me learn. Also the <?php doesnt matter.
 

gomarc

Member
Messages
516
Reaction score
18
Points
18
In your HTML code change line 13 to

<INPUT type="text" NAME="sender_email" SIZE=30></P>
 

dquigley

New Member
Messages
249
Reaction score
0
Points
0
BATMAN SAVES THE DAY AGAIN! TY Gomarc! You are THEMAN THEBATMAN!
 

tttony

Member
Messages
147
Reaction score
0
Points
16
problem solved... sorry I dont saw HTML code..

ok I just say one thing dquigley I like help people because at the same time I learn from other errors I like give advice about that errors and get good practices
 

dquigley

New Member
Messages
249
Reaction score
0
Points
0
Hey thx tony im glad ur here to help, it seems like I make a mistake in these every day so im sure ill need ur help again! THANKS GUYS!
 

brunoais

New Member
Messages
115
Reaction score
0
Points
0
serch for:
<P><strong>Your E-Mail Address:</strong><br>
at next line change:
<INPUT type="text" NAME="sender_name" SIZE=30></P>
to:
<INPUT type="text" NAME="
sender_email" SIZE=30></P>

When the page reloaded the $_Post['
sender_email'] was empty so it was returning to the form ;)
 
Top