| | |
php mail form - need to redirect to new page
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: May 2005
Posts: 1
Reputation:
Solved Threads: 0
I found a php mail form online that echos a text success message, but need to redirect it to a new page instead.
I love all the functions in the code except for the text echo.
I tried <input type="hidden" name="next-url" value="test.com">
and <? header(Location: file.php); ?>
but the form redirect is ignored
and the header location gives me an error of not being able to do it because header already exists
Any ideas?
Here is the code.
<html>
<head>
<title>PHP mail Form</title>
<?php
// START NECESSARY MODIFICATIONS
// your name
$recipientname = "YOUR NAME";
// your email
$recipientemail = "YOU@YOURDOMAIN.COM";
// subject of the email sent to you
$subject = "Online-Form Response for $recipientname";
// send an autoresponse to the user?
$autoresponse = "yes";
// subject of autoresponse
$autosubject = "Thank you for your mail!";
// autoresponse message
$automessage = "This is an auto response to let you know that we've successfully received your email sent through our email form. Thanks! We'll get back to you shortly.";
// thankyou displayed after the user clicks "submit"
$thanks = "Thank you for contacting us.<br>We will get back to you as soon as possible.<br>";
// END NECESSARY MODIFICATIONS
?>
</head>
<body>
<?php
if($_POST['submitform']) {
$Name = $HTTP_POST_VARS['Name'];
$Email = $HTTP_POST_VARS['Email'];
$Comments = $HTTP_POST_VARS['Comments'];
// check required fields
$dcheck = explode(",",$require);
while(list($check) = each($dcheck)) {
if(!$$dcheck[$check]) {
$error .= "Missing $dcheck[$check]<br>";
}
}
// check email address
if ((!ereg(".+\@.+\..+", $Email)) || (!ereg("^[a-zA-Z0-9_@.-]+$", $Email))){
$error .= "Invalid email address<br>";}
// display errors
if($error) {
?>
<b>Error</b><br>
<?php echo $error; ?><br>
<a href="#" onClick="history.go(-1)">try again</a>
<?php
}
else
{
$browser = $HTTP_USER_AGENT;
$ip = $REMOTE_ADDR;
// format message
$message = "Online-Form Response for $recipientname:
Name: $Name
Email: $Email
Comments: $Comments
-----------------------------
Browser: $browser
User IP: $ip";
// send mail and print success message
mail($recipientemail,"$subject","$message","From: $Name <$Email>");
if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($Email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
}
echo "$thanks";
}
}
else {
?>
<form name="contactform" action="<?php echo $PHP_SELF; ?>" method="post">
<input type="hidden" name="require" value="Name,Email,Comments">
<br>
Name <br>
<input name="Name" size="25">
<br>
<br>
E-mail<br>
<input name="Email" size="25">
<br>
<br>
Comments<br>
<textarea name="Comments" rows="5" cols="35"></textarea>
<br>
<br>
<input type="submit" value="Submit" name="submitform">
<input type="reset" value="Reset" name="reset">
</p>
<br>
</form>
<?php } ?>
</body>
</html>
I love all the functions in the code except for the text echo.
I tried <input type="hidden" name="next-url" value="test.com">
and <? header(Location: file.php); ?>
but the form redirect is ignored
and the header location gives me an error of not being able to do it because header already exists
Any ideas?
Here is the code.
<html>
<head>
<title>PHP mail Form</title>
<?php
// START NECESSARY MODIFICATIONS
// your name
$recipientname = "YOUR NAME";
// your email
$recipientemail = "YOU@YOURDOMAIN.COM";
// subject of the email sent to you
$subject = "Online-Form Response for $recipientname";
// send an autoresponse to the user?
$autoresponse = "yes";
// subject of autoresponse
$autosubject = "Thank you for your mail!";
// autoresponse message
$automessage = "This is an auto response to let you know that we've successfully received your email sent through our email form. Thanks! We'll get back to you shortly.";
// thankyou displayed after the user clicks "submit"
$thanks = "Thank you for contacting us.<br>We will get back to you as soon as possible.<br>";
// END NECESSARY MODIFICATIONS
?>
</head>
<body>
<?php
if($_POST['submitform']) {
$Name = $HTTP_POST_VARS['Name'];
$Email = $HTTP_POST_VARS['Email'];
$Comments = $HTTP_POST_VARS['Comments'];
// check required fields
$dcheck = explode(",",$require);
while(list($check) = each($dcheck)) {
if(!$$dcheck[$check]) {
$error .= "Missing $dcheck[$check]<br>";
}
}
// check email address
if ((!ereg(".+\@.+\..+", $Email)) || (!ereg("^[a-zA-Z0-9_@.-]+$", $Email))){
$error .= "Invalid email address<br>";}
// display errors
if($error) {
?>
<b>Error</b><br>
<?php echo $error; ?><br>
<a href="#" onClick="history.go(-1)">try again</a>
<?php
}
else
{
$browser = $HTTP_USER_AGENT;
$ip = $REMOTE_ADDR;
// format message
$message = "Online-Form Response for $recipientname:
Name: $Name
Email: $Email
Comments: $Comments
-----------------------------
Browser: $browser
User IP: $ip";
// send mail and print success message
mail($recipientemail,"$subject","$message","From: $Name <$Email>");
if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($Email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
}
echo "$thanks";
}
}
else {
?>
<form name="contactform" action="<?php echo $PHP_SELF; ?>" method="post">
<input type="hidden" name="require" value="Name,Email,Comments">
<br>
Name <br>
<input name="Name" size="25">
<br>
<br>
E-mail<br>
<input name="Email" size="25">
<br>
<br>
Comments<br>
<textarea name="Comments" rows="5" cols="35"></textarea>
<br>
<br>
<input type="submit" value="Submit" name="submitform">
<input type="reset" value="Reset" name="reset">
</p>
<br>
</form>
<?php } ?>
</body>
</html>
You may get error message by sending header after the <head> tag. You may want to replace the redirection header with javascript below:
<script language="JavaScript" type="text/JavaScript">
<!--
window.location.href = "http://www.yourdomain.net/yourpage.html";
//-->
</script>
zippee
-------------------------
www.basket2go.net
www.store2go.net
<script language="JavaScript" type="text/JavaScript">
<!--
window.location.href = "http://www.yourdomain.net/yourpage.html";
//-->
</script>
zippee
-------------------------
www.basket2go.net
www.store2go.net
![]() |
Similar Threads
- PHP mail Help (PHP)
- E-mail form data quick and easily with PHP (PHP)
- php flash mail (PHP)
- dreamweaver, PHP and submit form query (PHP)
Other Threads in the PHP Forum
- Previous Thread: Sokkit
- Next Thread: Hello Help I'm Wired PhP
| Thread Tools | Search this Thread |
5.2.10 action apache api array beginner binary broken cakephp checkbox class classes cms code cron curl database date destroy display dynamic echo echo$_get[x]changingitintovariable... email encode error fcc file files folder form forms function functions google header howtowriteathesis href htaccess html if-else image images include insert ip javascript joomla limit link local login mail memberships menu mlm mod_rewrite multiple multipletables mysql mysqlquery neutrality oop open passwords paypal pdf php provider query radio random record remote rss script search server sessions sockets source space sql strip_tags syntax system table template thesishelp tutorial update upload url validator variable video voteup web window.onbeforeunload=closeme; youtube





