Results 1 to 13 of 13
-
February 8th, 2010, 09:27 AM #1
How To: Redirect the Kirupa "PHP Contact Form"
One of the most common questions that people as is how to redirect the "PHP Contact Form". And since people either fail at searching or are just to lazy here's how you do it. Here's the final code from the tutorial:
changePHP Code:<?php
if(isset($_POST['submit'])) {
$to = "you@you.com";
$subject = "Form Tutorial";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
} else {
echo "blarg!";
}
?>
toPHP Code:echo "Data has been submitted to $to!";
PHP Code:header("Location: http://www.yourpage.com");
Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.
-
March 31st, 2010, 12:24 PM #24,865Registered User
postsSimp - I don't know if it will make a difference but you may want the header change to come after the call to the mail() function just in case the browser redirects before the email gets sent.
-
March 31st, 2010, 12:29 PM #3
Yea good suggestion. Didn't really think to much about it I just know this question is asked at least once a week. So for those reading this his suggestion is to turn:
toPHP Code:header("Location: http://www.yourpage.com");
mail($to, $subject, $body);
PHP Code:mail($to, $subject, $body);
header("Location: http://www.yourpage.com");
Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.
-
July 15th, 2010, 06:11 AM #430Registered User
postsOr maybe
PHP Code:<?php
if(isset($_POST['submit'])) {
$to = "you@you.com";
$subject = "Form Tutorial";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
if(mail($to, $subject, $body)){
// If the mail was sent, then redirect
header("Location: http://www.yourpage.com");
}else{
// Else display a message
echo 'An error occured while sending your message. Try again later';
}
} else {
//Display Form here
}
?>
-
August 30th, 2010, 10:50 AM #51Registered User
postsThe second one is worth
-
September 7th, 2010, 10:59 AM #61Registered User
poststhanks for handy piece of code, pretty use to read for newbie like me : ))
http://www.kirupa.com/forum/showthread.php?t=343513live chat support softwareLast edited by rich92018; September 8th, 2010 at 12:16 PM.
-
September 21st, 2010, 02:09 PM #71Registered User
postsMy form works with one exception - how do I redirect the page back to the contact form - instead of the php page?
PHP Code:
<?php
//Variables.
$user_email = $_REQUEST['email'];
$user_name = $_REQUEST['name'];
$user_subject = $_REQUEST['subject'];
$user_How= $_REQUEST['How'];
$user_comment = $_REQUEST['comment'];
$user_send = $_REQUEST['copy'];
$user_check = stripos("$user_email","@");
//Body of the email to be sent.
$body_mail = "Hello Christie, someone wants to contact you.. Details..
Name: $user_name $user_lastname
Email: $user_email
subject: $user_subject
How: $user_How
Comment: $user_comment.";
//Body of the Email for the user requesting a copy.
$body_email = "
Here is a copy of the email.
Your Name: $user_name $user_lastname.
Your Email: $user_email.
Your subject: $user_subject.
Your Comment: $user_comment.
Thank you for contacting us, we'll reply ASAP.
Yourwebsite team.";
//Check if the user submited the data require.
//If the @ is measing from the email address stop the user for continuing.
if ($user_check) {
echo "";
}
else {
echo "You can't continue with out a email address, Please enter a email address.";
exit ($user_check);
}
if (empty($user_name)) {
echo "<center><h2><font color='ff0000'>ERROR</font></h2></center>You didn't enter a your first name.<br>";
exit();
}
elseif (!$user_comment) {
echo "<center><h2><font color='ff0000'>ERROR</h2></center></font>Please enter a comment.";
die();
}
//Everything okay? send the e-mail.
else {
mail('customerservice@verysweetbabycakes.com','Email from YOURWEBITE',"$body_mail","from:YOURWEBSITE");
echo "your email was sent! Thank you.";
}
//If the checkbox if check send a copy to the user.
if (isset($user_send)) {
@mail("$user_email","The copy of your information from YOURWEBSITE","$body_email","YOURWEBSITE");
echo "And a copy of the Email was send to you!";
}
else {
die($user_send);
}
?>
HTML Code:
<head> <title>Contact Us</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-5" /> <link rel="stylesheet" type="text/css" href="style.css" /> <style type="text/css" media="all"> form, label, input { font-size : 1em; } fieldset { width : 36em; padding : 0.5em 1em; } label { float: left; position : relative; width : 15em; display : inline; margin : .5em .5em; } label.long { width : 12em; float: left; position : relative; width : 15em; display : inline; margin : .5em .5em;} label input { display: inline; left : 100%; top : 0px; width : 14em; } label.long input { width : 18em; } input.submit { margin-left : 15em; background-color: #CCCCCC; font-weight: bold; font-size: 12px; color: #C7377D; border=1px; border-color=#cc9999;} } br { clear: both; } </style> </head> <body> <p><center> <form action="mail.php" method="post" name="mail"> <input name="redirect" value="success.html" type="hidden" /> <fieldset> <legend>Contact Form</legend> <label> Your Name:<input name="name" > </label> <label>How did you hear about us:<br /> <select name="How"> <option value="Select One....." selected="selected">Select One</option> <option value="Friend">Friend</option> <option value="Yahoo">Yahoo</option> <option value="Google">Google</option> <option value="Other Search Engine">Other Search Engine</option> <option value="Flyer/Ad">Flyer/Ad</option> <option value="Other Website">Other Website</option> </select></label> <label>Subject/Topic:<br /> <select name="subject"> <option value="Select a topic....." selected="selected">Select a topic.....</option> <option value="Product Information">Product Information</option> <option value="Customer Support">Customer Support</option> <option value="Community Involvement">Community Involvement</option> <option value="Site Technical Issue">Site Technical Issue</option> <option value="Urgent">Urgent</option> <option value="Other">Other</option> </select></label> <label class="long">Email:<input name="email" /></label><br /> <label for="comments">Comments:<textarea name="comment" cols="40" rows="8">Type Comment Here </textarea></label> <br /><input value="Submit" type="submit" class="submit" /> </fieldset> </form></center>
-
January 9th, 2011, 04:18 PM #8
-
February 11th, 2011, 06:38 AM #91Registered User
postsHi Forum,
Abit of a neewbie to php, so i used this tutorial and got my contact form working, but if the user clicks submit without filling anything in, i get a whole heap of error messages, is there any way of guiding me on how to set up validation for cetain fields such as name, email etc....?
any help much appreciated...
Sukhi
-
June 9th, 2011, 06:54 AM #101Registered User
postsHey thanks for the tutorial - its works a treat thanks! I'm just starting out with php so this was exactly what I was looking for. I was wondering though once I have submitted the form the page refreshes and clears the form but there is no feedback to tell the user that the message has been received. I might be missing something but how do I achieve this?
thanks again, Jason
-
June 15th, 2011, 12:11 PM #111Registered User
postsCan somebody please help me?
I used the tutorial for the contact form, but somehow it's not working. When I submit the form I don't receive any message in my email. Can someone give me a suggestion?
Here are my codes:
<form method="POST" action="mailer.php">
<input type="text" name="name" size="19"><br>
<br>
<input type="text" name="email" size="19"><br>
<br>
<textarea rows="9" name="message" cols="30"></textarea>
<br>
<br>
<input type="submit" value="Submit" name="submit">
</form>
PHP:
<?php
if(isset($_POST['submit'])) {
$to = "veronikacabalova@hotmail.com";
$subject = "Form Tutorial";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
header("Location: http://www.dui-orland-lawyer.com");
mail($to, $subject, $body);
} else {
echo "blarg!";
}
?>
Thank You
-
June 25th, 2012, 06:16 AM #122Registered User
postsoutstanding and so helpful code i like it
-
February 21st, 2013, 06:51 AM #132Registered User
postsHi friends,
Can anyone tell me will it work with Prestashop?
Thanks

Reply With Quote



Bookmarks