Hi Guys
Having some problem redirecting to thank you page after php email form
I am using the script below any help appreciated
Many thanks
Silver500
---------------------------
<?php
// modify the four lines below
$emailaddress = "me@mydomain.com";
$fromaddress = "website@mydomain.com";
$subject = "A Website Message";
$thankyouPage = "thanks.php"; // put in a url (or relative page) to go to a Thank You page
// modify the four lines above
putenv('TZ=EST5EDT'); // eastern time
session_start();
function processMail($inputArray) {
// validation
if (!preg_match("([a-zA-Z]+)",$inputArray['name'])) $errors .= "Please enter your name<br />";
if (!preg_match("(^[-\w\.]+@([-a-z0-9]+\.)+[a-z]{2,4}$)i",$inputArray['email'])) $errors .= "Email address is not valid<br />";
if (!empty($inputArray[phone])) if (!preg_match("(^[-0-9\(\)\.]{7,}$)i",$inputArray[phone])) $errors .= "Phone number is not valid<br />";
if (!preg_match("([\w]+)",$inputArray['content'])) $errors .= "Your message is empty<br />";
// max messages
if (empty($errors)) $_SESSION['msgCount']++;
if ($_SESSION['msgCount'] >= "4") $errors .= "Messages have exceeded the maximum number allowed";
// stop if errors
if (!empty($errors)) { return "Your message was not sent<br />".$errors; }
// remove any input array variables not to be included in output email
unset($inputArray['send']);
// scrub variables
foreach ($inputArray as $key=>$value) {
$inputArray[$key] = trim($inputArray[$key]);
$inputArray[$key] = stripslashes($inputArray[$key]);
$inputArray[$key] = htmlspecialchars($inputArray[$key],ENT_QUOTES);
$inputArray[$key] = wordwrap($inputArray[$key],65,"<br />");
}
// need to use the config parms in this routine
global $subject,$emailaddress,$fromaddress,$thankyouPage;
// set headers
if (empty($fromaddress)) $fromaddress = $inputArray['email'];
$headers = 'MIME-Version: 1.0'."\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers .= "From: website<".$fromaddress.">\r\n";
// format message
$message = "<table cellpadding='5' border='1'>";
foreach ($inputArray as $key => $value) $message .="<tr><td><b>$key</b></td><td>$value</td></tr>";
$message .= "</table>";
// add source info to the message
$message .= "<br />Time of the message: ".date(" F d h:ia")."<br />";
$message .= "IP Address: ".$_SERVER['REMOTE_ADDR']."<br />";
$message .= "Hostname: ".gethostbyaddr($_SERVER['REMOTE_ADDR'])."<br />";
// send message
if (!mail($emailaddress,$subject,$message,$headers)) return "There was a processing error<br />Your message was not sent";
if (!empty($thankyouPage)) { header('location: '.$thankyouPage); die(); }
global $_POST; unset($_POST);
return "Thank you<br />Your message has been sent";
}
if (!isset($_SESSION['msgCount'])) $_SESSION['msgCount'] = 0;
if (isset($_POST['send']) AND isset($_SESSION['msgCount'])) $message = processMail($_POST);
if (!empty($_POST)) {
foreach ($_POST as $key=>$value) {
$_POST[$key] = stripslashes($_POST[$key]);
$_POST[$key] = htmlspecialchars($_POST[$key],ENT_QUOTES);
}
}
?>
<html>
<head>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
<div style="text-align: center; padding: 20px; width: 500px; margin: 50px auto; border: solid 1px black;">
<span style="font-weight: bold;">Contact Us</span><br><br>
your name<br><input type="text" style="width: 330px;" name="name" value="<?php echo $_POST['name']; ?>" maxlength="50"><br><br>
your email address<br><input type="text" style="width: 330px;" name="email" value="<?php echo $_POST['email']; ?>" maxlength="50"><br><br>
your phone number<br><input type="text" style="width: 330px;" name="phone" value="<?php echo $_POST['phone']; ?>" maxlength="50"><br><br>
your message<br><textarea name="content" style="resize: none; width: 330px; height: 100px;"><?php echo $_POST['content']; ?></textarea>
<br><br>
<input type="submit" name="send" value="submit">
<div style="margin-top: 10px; color: firebrick;"><?php echo $message; ?></div>
</div>
</form>
</body></html>