The following is the code on the actual contact page.
Code: Select all
<form action="" method="post" class="ajax_form">
<fieldset><?php if (!isset($error) || $error == true){ ?><legend><span>Send a message</span></legend>
<p class="<?php echo $the_nameclass; ?>" ><input name="yourname" class="text_input empty" type="text" id="name" size="20" value='<?php echo $the_name?>'/><label for="name">Your Name*</label>
</p>
<p class="<?php echo $the_companynameclass; ?>" ><input name="companyname" class="text_input empty" type="text" id="name" size="30" value='<?php echo $the_companyname?>'/>
<label for="name">Company Name</label>
</p>
<p class="<?php echo $the_emailclass; ?>" ><input name="email" class="text_input email" type="text" id="email" size="20" value='<?php echo $the_email?>' /><label for="email">E-Mail*</label></p>
<p>
<input name="website" class="text_input" type="text" id="website" size="20" value="<?php echo $the_website?>"/><label for="website">Website</label></p>
Request Type:
<select name="requesttype" id="requesttype"value="<?php echo $the_requesttype?>">
<option value="General">General Inquiry</option>
<option value="Quote">Service Quote</option>
</select>
<label for="message" class="blocklabel">Your Message*</label>
<p class="<?php echo $the_messageclass; ?>"><textarea name="message" class="text_area empty" cols="40" rows="7" id="message" ><?php echo $the_message ?></textarea></p>
<p>
<input type="hidden" id="myemail" name="myemail" value="<?php echo $email_adress_reciever; ?>" />
<input type="hidden" id="myblogname" name="myblogname" value="<?php echo $name_of_your_site; ?>" />
<input name="Send" type="submit" value="Send" class="button" id="send" size="16"/></p>
<?php } else { ?>
<p><h3>Your message has been sent!</h3> Thank you!</p>
<?php } ?>
</fieldset>
</form>The following is the code on the send.php page.
Code: Select all
<?php
if(isset($_POST['Send'])){
$error = false;
$the_name = $_POST['yourname'];
$the_companyname = $_POST['companyname'];
$the_email = $_POST['email'];
$the_website = $_POST['website'];
$the_requesttype = $_POST['requesttype'];
$the_message = $_POST['message'];
if(!checkmymail($the_email))
{
$error = true;
$the_emailclass = "error";
}else{
$the_emailclass = "valid";
}
if($the_name == "")
{
$error = true;
$the_nameclass = "error";
}else{
$the_nameclass = "valid";
}
if($the_message == "")
{
$error = true;
$the_messageclass = "error";
}else{
$the_messageclass = "valid";
}
if($error == false)
{
$to = $_POST['myemail'];
$subject = "New Message from " . $_POST['myblogname'];
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$header .= 'From:'. $_POST['email'] . " \r\n";
$message1 = nl2br($_POST['message']);
$message = "New message from $the_name <br/>
Inquiry Type: $the_requesttype <br/>
Company Name: $the_companyname <br/>
Mail: $the_email<br />
Website: $the_website <br /><br />
Message: $message1 <br />"
;
mail($to,
$subject,
$message,
$header);
if(isset($_POST['ajax'])){
echo"<h3>Your message has been sent!</h3><p> Thank you!</p>";
}
}
}
function checkmymail($mailadresse){
$email_flag=preg_match("!^\w[\w|\.|\-]+@\w[\w|\.|\-]+\.[a-zA-Z]{2,4}$!",$mailadresse);
return $email_flag;
}
?>