 |
 |
PHP Feedback form redirects
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2004
Status:
Offline
|
|
I am having a problem with a PHP feedback form. I'm still learning PHP so please help.
I have a feedback form on a contact page. It works fine and sends an email to my inbox but I don't know how to create a redirect to a thank you page. I tried a solution I found on a wizard site but the redirect fails. In the mean time I have set up a simple page that has an echo script that says thank you. This is my feedback form in html
<form action="sendmail.php" method="POST">
<table border="0" cellpadding="8" cellspacing="8" summary="feedback form">
<tr><td><p>Your name :</p></td><td><input type="text" name="name" size="25" /></td></tr>
<tr><td><p>Your e-mail :</p></td><td><input type="text" name="email" size="25" /></td></tr>
<tr>
<td colspan="2">
<p>Message</p>
<textarea rows="15" cols="45" name="message"></textarea>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="Send Message">
<br />
</td></p>
</tr>
</table>
</form>
This is my PHP script
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
//Save visitor name and entered message into one variable:
$formcontent="VISITOR NAME: $name\n\nFEEDBACK: $message";
$recipient = "supermario@my example blog.com";
$subject = "Message from Contact Page";
$mailheader = "From: $email\r\n";
$mailheader .= "Reply-To: $email\r\n";
$mailheader .= "MIME-Version: 1.0\r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Failure!");
echo "Thank You! I'll be in touch with you soon";
?>
How do I fix the PHP script to direct the message sender to a thankyou.html page so they can carry on reading?
|
|
Anyone who denies climate changes naturally is a Climate Change Skeptic.
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Jan 2001
Location: Salt Lake City, UT USA
Status:
Offline
|
|
header("Location: thankyou.html");
|
|
2008 iMac 3.06 Ghz, 2GB Memory, GeForce 8800, 500GB HD, SuperDrive
8gb iPhone on Tmobile
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2004
Status:
Offline
|
|
Before I try it is this OK?
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
//Save visitor name and entered message into one variable:
$formcontent="VISITOR NAME: $name\n\nFEEDBACK: $message";
$recipient = "supermario@my example blog.com";
$subject = "Message from Contact Page";
$mailheader = "From: $email\r\n";
$mailheader .= "Reply-To: $email\r\n";
$mailheader .= "MIME-Version: 1.0\r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Failure!");
header("Location: thankyou.html");
?>
|
|
Anyone who denies climate changes naturally is a Climate Change Skeptic.
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2003
Location: London
Status:
Offline
|
|
could use:
Code:
$mail_sent = mail($recipient, $subject, $formcontent, $mailheader);
if($mail_sent==true){
header("Location: thankyou.html");
} else {
//error handling
}
that way you are sure the mail is sent.
I'd also suggest removing the \r from your code as some email checkers identify this as a virus attack.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2004
Status:
Offline
|
|
Originally Posted by moodymonster
could use:
I'd also suggest removing the \r from your code as some email checkers identify this as a virus attack.
Thanks, learning more now. Bear with me as most of that was from sitewizard and I don't know what some variables like /r do.
What do /r and /n do?
If I remove /r and merge your code with what I have is this perfect now (without errors too)?
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
//Save visitor name and entered message into one variable:
$formcontent="VISITOR NAME: $name\n\nFEEDBACK: $message";
$recipient = "supermario@my example blog.com";
$subject = "Message from Contact Page";
$mailheader = "From: $email\n";
$mailheader .= "Reply-To: $email\n";
$mailheader .= "MIME-Version: 1.0\n";
$mail_sent = mail($recipient, $subject, $formcontent, $mailheader);
if($mail_sent==true){
header("Location: thankyou.html");
} else {
//error handling
}
?>
|
|
Anyone who denies climate changes naturally is a Climate Change Skeptic.
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2003
Location: London
Status:
Offline
|
|
yes, that looks good.
replace
with
Code:
echo 'error sending email';
that way it will give an error message.
// is just a way of leaving comments for humans in the code, ie the computer ignores anything prefixed with //. You can also use it to comment out code you don't want used. You can also use /* at the start of a section, and */ at the end to comment out a whole block of text/code.
\r and \n are different ways of entering a newline.
Personally I use:
http://phpmailer.sourceforge.net/
for email, a little while ago I needed to be able to send attachments from an online form. Using phpmailer was the easiest option.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Jan 2001
Location: Salt Lake City, UT USA
Status:
Offline
|
|
Originally Posted by Super Mario
Thanks, learning more now. Bear with me as most of that was from sitewizard and I don't know what some variables like /r do.
What do /r and /n do?
If I remove /r and merge your code with what I have is this perfect now (without errors too)?
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
//Save visitor name and entered message into one variable:
$formcontent="VISITOR NAME: $name\n\nFEEDBACK: $message";
$recipient = "supermario@my example blog.com";
$subject = "Message from Contact Page";
$mailheader = "From: $email\n";
$mailheader .= "Reply-To: $email\n";
$mailheader .= "MIME-Version: 1.0\n";
$mail_sent = mail($recipient, $subject, $formcontent, $mailheader);
if($mail_sent==true){
header("Location: thankyou.html");
} else {
//error handling
}
?>
The \r and \n are carriage return and newline characters respectively... they essentially do the same thing, but are legacy carry overs from eras past. Well, \r is, \n is standard.
Your code looks good.
Although not a big deal by any means, you can make your success checking simpler.
if($mail_sent){
...
|
|
2008 iMac 3.06 Ghz, 2GB Memory, GeForce 8800, 500GB HD, SuperDrive
8gb iPhone on Tmobile
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2004
Status:
Offline
|
|
You guys have been great. One last question before I try the code. In my code I have:
$mailheader = "From: $email\n";
$mailheader .= "Reply-To: $email\n";
Why is there a period before = (.=) in a couple of lines? Also, why do some PHP scripts start <?php while others simply start with <?
If that doesn't need to be changed tomorrow I will try either:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
//Save visitor name and entered message into one variable:
$formcontent="VISITOR NAME: $name\n\nFEEDBACK: $message";
$recipient = "supermario@my example blog.com";
$subject = "Message from Contact Page";
$mailheader = "From: $email\n";
$mailheader .= "Reply-To: $email\n";
$mailheader .= "MIME-Version: 1.0\n";
$mail_sent = mail($recipient, $subject, $formcontent, $mailheader);
if($mail_sent==true){
header("Location: thankyou.html");
} else {
echo 'Sorry there was an error sending your message. Please try again.';
}
?>
Or with the simpler mail_sent
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
//Save visitor name and entered message into one variable:
$formcontent="VISITOR NAME: $name\n\nFEEDBACK: $message";
$recipient = "supermario@my example blog.com";
$subject = "Message from Contact Page";
$mailheader = "From: $email\n";
$mailheader .= "Reply-To: $email\n";
$mailheader .= "MIME-Version: 1.0\n";
$mail_sent = mail($recipient, $subject, $formcontent, $mailheader);
if($mail_sent){
header("Location: thankyou.html");
} else {
echo 'Sorry there was an error sending your message. Please try again.';
}
?>
|
|
Anyone who denies climate changes naturally is a Climate Change Skeptic.
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Jan 2001
Location: Salt Lake City, UT USA
Status:
Offline
|
|
Originally Posted by Super Mario
You guys have been great. One last question before I try the code. In my code I have:
$mailheader = "From: $email\n";
$mailheader .= "Reply-To: $email\n";
Why is there a period before = (.=) in a couple of lines? Also, why do some PHP scripts start <?php while others simply start with <?
The period in PHP is a concatication character. It combines data together. For instance:
$string = "this is" . " a string" ;
makes $string = "this is a string". When you use the operator " .= ", it adds the data to the variable. Instead of setting the variable to something, you're adding to it.
So when you run this script, you get:
$mailheader = From: $email\nReply-To: $email\n
As for the delimiters <? and <?php , they both work, but <?php is better form.
|
|
2008 iMac 3.06 Ghz, 2GB Memory, GeForce 8800, 500GB HD, SuperDrive
8gb iPhone on Tmobile
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Jan 2001
Location: Salt Lake City, UT USA
Status:
Offline
|
|
|
|
|
2008 iMac 3.06 Ghz, 2GB Memory, GeForce 8800, 500GB HD, SuperDrive
8gb iPhone on Tmobile
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2004
Status:
Offline
|
|
Works great, thanks 
|
|
Anyone who denies climate changes naturally is a Climate Change Skeptic.
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|