|
Posted by Andy on 09/15/05 01:50
I am new to PHP so please help me to solve my problem.
I found a website where I generated following PHP script. It works fine but
I would like it to integrate in my contact page, so messages like :
That is not a valid email address, You didn't fill in these required fields:
or Thank you for your feedback would appear in the Contact page instead on
the page generated by the script.
Thank You for your help.
<?
// This is the beginning of the PHP code
#####################################################################
# #
# Contact Form Generator #
# by Robert Packer #
# rob_packer@yahoo.com #
# Don't forget to vote at hotscripts.com #
# http://www.hotscripts.com/Detailed/30983.html #
# I also subcontract larger projects #
# #
#####################################################################
$name = $_POST['name'];
$address = $_POST['address'];
$state = $_POST['state'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$fax = $_POST['fax'];
$error_msg = "";
$msg = "";
if(!$address){
$error_msg .= "Your address \n";
}
if($address){
$msg .= "Address: \t $address \n";
}
if(!$city){
$error_msg .= "Your City \n";
}
if($city){
$msg .= "City: \t $city \n";
}
if(!$state){
$error_msg .= "Your State \n";
}
if($state){
$msg .= "State: \t $state \n";
}
if(!$country){
$error_msg .= "Your country \n";
}
if($country){
$msg .= "Country: \t $country \n";
}
if(!$email){
$error_msg .= "Your email \n";
}
if($email){
if(!eregi("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\._\-]+\.[a-zA-Z]{2,4}", $email)){
echo "\n<br>That is not a valid email address. Please <a
href=\"javascript:history.back()\">return</a> to the previous page and try
again.\n<br>";
exit;
}
$msg .= "Email: \t $email \n";
}
if($comments){
$msg .= "Comments: \t $comments \n";
}
$sender_email="";
if(!isset($name)){
if($name == ""){
$sender_name="Web Customer";
}
}else{
$sender_name=$name;
}
if(!isset($email)){
if($email == ""){
$sender_email="Customer@website.com";
}
}else{
$sender_email=$email;
}
if($error_msg != ""){
echo "You didn't fill in these required fields:<br>"
.nl2br($error_msg) .'<br>Please <a
href="javascript:history.back()">return</a> to the previous page and try
again.';
exit;
}
$mailheaders = "MIME-Version: 1.0\r\n";
$mailheaders .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$mailheaders .= "From: $sender_name <$sender_email>\r\n";
$mailheaders .= "Reply-To: $sender_email <$sender_email>\r\n";
mail("webmaster@yoursite.com","Contact",stripslashes($msg), $mailheaders);
echo "<html>\n<head>\n<title>Thanks For Your
Submission</title>\n</head>\n<body>\n<h2>Thank you for your feedback
$name</h2>\n";echo '<b>This is the information you submitted</b>'."<br>\n";
echo nl2br(stripslashes($msg));
echo '<br><br></body></html>';
//This is the end of the PHP code
?>
Navigation:
[Reply to this message]
|