Hi,
Im changing all my forms to php for more sucurity and am fairly new to php. I have the following script which i want to tweek a little. Instead of a message coming up when the form has been succesfully submitted i want to redirect to a thankyou page. I cant work out how to do this. Can anybody help
Thanks
Ben
<?
if($_POST['Submit']){
// This is only called when the form is submitted.
// Get the Variables From the Form
$name = $_POST['name'];
$email = $_POST['email'];
$reason = $_POST['reason'];
$besttime = $_POST['time'] . ' ' . $_POST['nightorday'] ;
$message = $_POST['message'];
// Set the variables to send an email to the Owner and Sender (this message will be send with HTML, to send this
// Email using Text, All you have to do write the message like this:
// $message = ' Thank you for sending and email'; ect...
// This is the Subject of this message
$subj= "Christmas Gift Voucher";
// Headers will included The From, Return Email
$header = "Return-Path: benerskine@noble-manhattan.com\r\n";
$header .= "From: Noble Manhattan Coaching Ltd <#@#.com>\r\n";
// Header also include the Type, and Language the Email being sent, E.g. for Arabic Typed Email
// You will use iso-1256
$header .= "Content-Type: text/html; charset=iso-8859-1;\n\n\r\n";
//Message for the Owner
$ownermes = '<p><b>W&P </b></p>
<p align="justify"><b>The Contact Person\'s Name Is:<font color="blue"> ' . $name . ' </font></b></p>
<p align="justify"><b>Their E-Mail is: <a href=mailto:' . $email . '>' . $email . '</a> </b></p>
<p align="justify"><b>Their Telephone Number is:<font color="blue"> ' . $phone . '</font> </b></p>
<p align="justify"><b>Their Best time to contact:<font color="blue"> ' . $besttime . ' </font></b></p>
<p align="justify"><b>Their Reason Of Contact is:<font color="blue"> ' . $reason . '</font> </b></p>
<p align="justify"><b>The Message they wrote was:<font color="blue"> ' . $message . '</font> </b></p>
<p><b>Thank You For Using Sample Site As Your Personal Design</b></p>
<p><b>Sample Site Inc. Website Manager,</b></p>
';
//Message for the sender
$sednermess = '<p><b>Thank You, ' . $name .' For contacting W&P Assessment and Training Centre</b></p>
<p align="justify"><b>We have recieved your message. Someone will return Your Message
As soon as possible, Thank you for your interest. </b></p>
<p><b>W&P Assessment and Training Centre</b></p>
';
// This is the email of the owner
$to = '#@.co.uk';
//This will actually send the emails
// Send one to the owner
mail ($to,"$subj",$ownermes,$header);
// Send one to the sender (thank you message)
mail ($email,"$subj",$sednermess,$header);
// This message will show on the board for the customer to OK everything
// Explode the name, so we only show the first name
$newname = explode(' ',$name );
$message = 'Your Email Has Been Sent, Thank You: ' . $newname[0] . '.';
}
// End of Send mail, Show Form, With Either The Message, or New
?>
<html>
<head>
<title>Contact Us :: Sample Company</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="<? echo $_SERVER['PHP_SELF'];?>" method="post" name="contactus" id="contactus" onSubmit="return validateme(this)">
<table width="500" align="center" cellpadding="5" cellspacing="5">
<?
// This is the message you that will show ONLY when the form is completely submitted and the email was sent!
if($message != NULL) { ?>
<tr>
<td colspan="2"><div align="center"><strong><font color="#FF0000" face="Verdana, Arial, Helvetica, sans-serif"><? echo $message;?></font></strong></div></td>
</tr>
<tr>
<? } ?>
<td colspan="2"><div align="center"><font face="Georgia, Times New Roman, Times, serif"><strong>Contact
Us:</strong></font></div></td>
</tr>
<tr>
<td width="227"><font face="Georgia, Times New Roman, Times, serif"><strong>Your
Name:</strong><font color="#FF0000">*</font></font></td>
<td width="236"><font face="Georgia, Times New Roman, Times, serif">
<input name="name" type="text" id="name" size="30" style="font-weight:bold;">
</font></td>
</tr>
<tr>
<td><font face="Georgia, Times New Roman, Times, serif"><strong>Your E-mail:</strong><font color="#FF0000">*</font></font></td>
<td><font face="Georgia, Times New Roman, Times, serif">
<input name="email" type="text" id="email" size="30" style="font-weight:bold;">
</font></td>
</tr>
<tr>
<td><font face="Georgia, Times New Roman, Times, serif"><strong>Your Reason
of Contact:</strong><font color="#FF0000">*</font></font></td>
<td><font face="Georgia, Times New Roman, Times, serif">
<select name="reason" id="reason" style="width:115px;font-weight:bold;">
<option value="Billing">Billing</option>
<option value="Comments">Comments</option>
<option value="Complaints">Complaints</option>
<option>Sales</option>
<option value="Support" selected>Support</option>
</select>
</font></td>
</tr>
<tr>
<td><font face="Georgia, Times New Roman, Times, serif"><strong>Best Time
To Call:</strong></font></td>
<td><font face="Georgia, Times New Roman, Times, serif"> <strong><font face="Georgia, Times New Roman, Times, serif">
<select name="time" id="time" style="width:115px;font-weight:bold;">
<option value="12:00">12:00</option>
<option value="12:30">12:30</option>
<option value="1:00">1:00</option>
<option value="1:30">1:30</option>
<option value="2:00">2:00</option>
<option value="2:30" selected>2:30</option>
<option value="3:00">3:00</option>
<option value="3:30">3:30</option>
<option value="4:00">4:00</option>
<option value="4:30">4:30</option>
<option value="5:00">5:00</option>
<option value="5:30">5:30</option>
</select>
<input type="radio" name="nightorday" value="am" class="buton">
<font size="2">AM
<input name="nightorday" type="radio" value="pm" checked class="buton">
PM</font></font></strong> </font></td>
</tr>
<tr>
<td><font face="Georgia, Times New Roman, Times, serif"><strong>Your Message:</strong><font color="#FF0000">*</font></font></td>
<td><font face="Georgia, Times New Roman, Times, serif">
<textarea name="message" id="message" style="width:215px;font-weight:bold;height:50px;"></textarea>
</font><font face="Georgia, Times New Roman, Times, serif"> </font></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="Send Contact Request" style="background-color:#CC0099;font-weight:bold;color:white;">
</div></td>
</tr>
</table>
</form>
</body>
</html>
<script>
// check the form
function validateme(thisform){
var isvalid = true;
if(thisform.name.value.length <3){
// invalid Message
alert("Please Enter A Valid Name, At Least 3 Characters Minimum!");
isvalid = false
thisform.name.focus();
}
if(isvalid){
if (thisform.email.value.indexOf("@")==-1 || thisform.email.value.indexOf(".")==-1 || thisform.email.value.indexOf(" ")!=-1 || thisform.email.value.length<6){
// invalid Message
alert("Please Enter A Valid Email!");
isvalid = false
thisform.email.focus();
}
}
if(isvalid){
if(thisform.message.value.length <3){
// invalid Message
alert("Please Enter A Valid Message, At Least 3 Characters Minimum!");
isvalid = false
thisform.message.focus();
}
}
return isvalid;
}
</script>
Im changing all my forms to php for more sucurity and am fairly new to php. I have the following script which i want to tweek a little. Instead of a message coming up when the form has been succesfully submitted i want to redirect to a thankyou page. I cant work out how to do this. Can anybody help
Thanks
Ben
<?
if($_POST['Submit']){
// This is only called when the form is submitted.
// Get the Variables From the Form
$name = $_POST['name'];
$email = $_POST['email'];
$reason = $_POST['reason'];
$besttime = $_POST['time'] . ' ' . $_POST['nightorday'] ;
$message = $_POST['message'];
// Set the variables to send an email to the Owner and Sender (this message will be send with HTML, to send this
// Email using Text, All you have to do write the message like this:
// $message = ' Thank you for sending and email'; ect...
// This is the Subject of this message
$subj= "Christmas Gift Voucher";
// Headers will included The From, Return Email
$header = "Return-Path: benerskine@noble-manhattan.com\r\n";
$header .= "From: Noble Manhattan Coaching Ltd <#@#.com>\r\n";
// Header also include the Type, and Language the Email being sent, E.g. for Arabic Typed Email
// You will use iso-1256
$header .= "Content-Type: text/html; charset=iso-8859-1;\n\n\r\n";
//Message for the Owner
$ownermes = '<p><b>W&P </b></p>
<p align="justify"><b>The Contact Person\'s Name Is:<font color="blue"> ' . $name . ' </font></b></p>
<p align="justify"><b>Their E-Mail is: <a href=mailto:' . $email . '>' . $email . '</a> </b></p>
<p align="justify"><b>Their Telephone Number is:<font color="blue"> ' . $phone . '</font> </b></p>
<p align="justify"><b>Their Best time to contact:<font color="blue"> ' . $besttime . ' </font></b></p>
<p align="justify"><b>Their Reason Of Contact is:<font color="blue"> ' . $reason . '</font> </b></p>
<p align="justify"><b>The Message they wrote was:<font color="blue"> ' . $message . '</font> </b></p>
<p><b>Thank You For Using Sample Site As Your Personal Design</b></p>
<p><b>Sample Site Inc. Website Manager,</b></p>
';
//Message for the sender
$sednermess = '<p><b>Thank You, ' . $name .' For contacting W&P Assessment and Training Centre</b></p>
<p align="justify"><b>We have recieved your message. Someone will return Your Message
As soon as possible, Thank you for your interest. </b></p>
<p><b>W&P Assessment and Training Centre</b></p>
';
// This is the email of the owner
$to = '#@.co.uk';
//This will actually send the emails
// Send one to the owner
mail ($to,"$subj",$ownermes,$header);
// Send one to the sender (thank you message)
mail ($email,"$subj",$sednermess,$header);
// This message will show on the board for the customer to OK everything
// Explode the name, so we only show the first name
$newname = explode(' ',$name );
$message = 'Your Email Has Been Sent, Thank You: ' . $newname[0] . '.';
}
// End of Send mail, Show Form, With Either The Message, or New
?>
<html>
<head>
<title>Contact Us :: Sample Company</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="<? echo $_SERVER['PHP_SELF'];?>" method="post" name="contactus" id="contactus" onSubmit="return validateme(this)">
<table width="500" align="center" cellpadding="5" cellspacing="5">
<?
// This is the message you that will show ONLY when the form is completely submitted and the email was sent!
if($message != NULL) { ?>
<tr>
<td colspan="2"><div align="center"><strong><font color="#FF0000" face="Verdana, Arial, Helvetica, sans-serif"><? echo $message;?></font></strong></div></td>
</tr>
<tr>
<? } ?>
<td colspan="2"><div align="center"><font face="Georgia, Times New Roman, Times, serif"><strong>Contact
Us:</strong></font></div></td>
</tr>
<tr>
<td width="227"><font face="Georgia, Times New Roman, Times, serif"><strong>Your
Name:</strong><font color="#FF0000">*</font></font></td>
<td width="236"><font face="Georgia, Times New Roman, Times, serif">
<input name="name" type="text" id="name" size="30" style="font-weight:bold;">
</font></td>
</tr>
<tr>
<td><font face="Georgia, Times New Roman, Times, serif"><strong>Your E-mail:</strong><font color="#FF0000">*</font></font></td>
<td><font face="Georgia, Times New Roman, Times, serif">
<input name="email" type="text" id="email" size="30" style="font-weight:bold;">
</font></td>
</tr>
<tr>
<td><font face="Georgia, Times New Roman, Times, serif"><strong>Your Reason
of Contact:</strong><font color="#FF0000">*</font></font></td>
<td><font face="Georgia, Times New Roman, Times, serif">
<select name="reason" id="reason" style="width:115px;font-weight:bold;">
<option value="Billing">Billing</option>
<option value="Comments">Comments</option>
<option value="Complaints">Complaints</option>
<option>Sales</option>
<option value="Support" selected>Support</option>
</select>
</font></td>
</tr>
<tr>
<td><font face="Georgia, Times New Roman, Times, serif"><strong>Best Time
To Call:</strong></font></td>
<td><font face="Georgia, Times New Roman, Times, serif"> <strong><font face="Georgia, Times New Roman, Times, serif">
<select name="time" id="time" style="width:115px;font-weight:bold;">
<option value="12:00">12:00</option>
<option value="12:30">12:30</option>
<option value="1:00">1:00</option>
<option value="1:30">1:30</option>
<option value="2:00">2:00</option>
<option value="2:30" selected>2:30</option>
<option value="3:00">3:00</option>
<option value="3:30">3:30</option>
<option value="4:00">4:00</option>
<option value="4:30">4:30</option>
<option value="5:00">5:00</option>
<option value="5:30">5:30</option>
</select>
<input type="radio" name="nightorday" value="am" class="buton">
<font size="2">AM
<input name="nightorday" type="radio" value="pm" checked class="buton">
PM</font></font></strong> </font></td>
</tr>
<tr>
<td><font face="Georgia, Times New Roman, Times, serif"><strong>Your Message:</strong><font color="#FF0000">*</font></font></td>
<td><font face="Georgia, Times New Roman, Times, serif">
<textarea name="message" id="message" style="width:215px;font-weight:bold;height:50px;"></textarea>
</font><font face="Georgia, Times New Roman, Times, serif"> </font></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="Send Contact Request" style="background-color:#CC0099;font-weight:bold;color:white;">
</div></td>
</tr>
</table>
</form>
</body>
</html>
<script>
// check the form
function validateme(thisform){
var isvalid = true;
if(thisform.name.value.length <3){
// invalid Message
alert("Please Enter A Valid Name, At Least 3 Characters Minimum!");
isvalid = false
thisform.name.focus();
}
if(isvalid){
if (thisform.email.value.indexOf("@")==-1 || thisform.email.value.indexOf(".")==-1 || thisform.email.value.indexOf(" ")!=-1 || thisform.email.value.length<6){
// invalid Message
alert("Please Enter A Valid Email!");
isvalid = false
thisform.email.focus();
}
}
if(isvalid){
if(thisform.message.value.length <3){
// invalid Message
alert("Please Enter A Valid Message, At Least 3 Characters Minimum!");
isvalid = false
thisform.message.focus();
}
}
return isvalid;
}
</script>