I have seen lots of questions about this on here and have taken the code I have now from several answers.
But for some reason I cant get it to work and I cant figure out why.
I have a HTML form with the code here:
<form id="quick_contact" name="quick_contact" action="" method="POST">
<div class="input-control text">
<input id="name" name="name" type="text" value="" placeholder="Enter name here">
</div>
<div class="space10"> </div>
<div class="input-control email">
<input id="email" name="email" type="email" value="" placeholder="Enter email address here"/>
</div>
<div class="space10"> </div>
<div class="input-control textarea">
<textarea id="comments" name="comments" placeholder="Enter Comments Here"></textarea>
</div>
<div class="space10"> </div>
<button id="quick_submit" name="quick_submit" onclick="quickContact()">Send</button>
</form>
And I have my jquery here UPDATED as of Thomas' answer:
<script type="text/javascript">
function quickContact(){
$.ajax({
type: "POST",
url: "quick-contact.php",
data:
{
name: $('#name').val().trim(),
email: $('#email').val().trim(),
comments: $('#comments').val().trim(),
},
success: function(html) {
var submitted = $.trim(html);
if (submitted) {
alert("Thanks for your submission");
$('#quick_contact')[0].reset();
return;
} else {
alert("Failed to submit.");
return false;
}
}
});
};
</script>
And here is the PHP which handles the email side of things in a file called "quick-contact.php again updated as of Thomas' answer:
if(isset($_POST) == true){
$status = 1 // init to one, assume there will not be an error
//Store the entered values in the variables
$name = mysql_escape_string(trim($_POST['name']));
$email = mysql_escape_string(trim($_POST['email']));
$comments = mysql_escape_string(trim($_POST['comments']));
$comments = str_replace('\r\n','<br>',$comments);
// EMAIL HEADERS
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=utf-8\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
$headers .= "X-Mailer: php\n";
$headers .= "From: *****<*****#l*****>\n";
//SEND EMAIL TO BRANCH
// EMAIL TITLE
$subject = $name . " " . get_content(3344);
//message
$message1 = "<style type=\"text/css\">";
$message1 .= "div { font-family: Arial, Verdana, Tahoma; font-size: 10pt; line-height: 120%; }";
$message1 .= "h1 { margin: 0; font-size: 14pt; }";
$message1 .= "h2 { margin: 0; font-size: 12pt; }";
$message1 .= "span { font-size: 9pt; font-weight: bold; }";
$message1 .= "</style>\n";
$message1 .= "<div>";
$message1 .= "<p>" . $name . " " . get_content(3344) . "</p>\n";
$message1 .= "<p>" . get_content(3345) . "</p>\n";
$message1 .= "<p><b>" . ucwords(get_content(2869)) . ":</b> " . $name . "<br />";
$message1 .= "<b>" . ucwords(get_content(27)) . ":</b> " . $email . "<br />";
$message1 .= "<b>" . ucwords(get_content(1258)) . ":</b> " . $comments . "<br />";
$message1 .= "</p>\n";
$message1 .= get_content(893); // King Regards,
$message1 .= "<br /><br />";
$message1 .= "<img src=\"***********\" alt=\"*******\">";
$message1 .= "<br />";
$message1 .= "</div>";
//SEND CUSTOMER AN EMAIL
// EMAIL TITLE
$subject2 = get_content(392);
//message
$message2 = "<style type=\"text/css\">";
$message2 .= "div { font-family: Arial, Verdana, Tahoma; font-size: 10pt; line-height: 120%; }";
$message2 .= "h1 { margin: 0; font-size: 14pt; }";
$message2 .= "h2 { margin: 0; font-size: 12pt; }";
$message2 .= "span { font-size: 9pt; font-weight: bold; }";
$message2 .= "</style>\n";
$message2 .= "<div>";
$message2 .= "<p>" . $name . ",</p>\n";
$message2 .= "<p>" . get_content(392) . "</p>\n";
$message2 .= "<p>" . str_replace("{TEL_NUMBER}", $header_branch_details[0]['Tel'], str_replace("{BRANCH_EMAIL}", $header_branch_details[0]['SalesEmail'], get_content(2764))) . "</p>\n";
$message2 .= get_content(893); // King Regards,
$message2 .= "<br /><br />";
$message2 .= "<img src=\"*********\" alt=\"*********\">";
$message2 .= "<br />";
$message2 .= "</div>";
//Send branch email
$success = mail('***#****.com', $subject, $message1, $headers);
//Send customer email
$success2 = mail($email, $subject2, $message2, $headers);
if (!$success) {
$status = 0;
}
echo $status;
}
Sorry about the mass of code I really hope someone can help me here
Change the submit type to a button type with an onClick event that calls doSomething().
Then, have doSomething() run the ajax call, like so:
function doSomething() {
$.ajax({
type: 'post',
url: 'quick-contact.php',
data:
{
name: $('#name').val().trim(),
email: $('#email').val().trim(),
comments: $('#comments').val().trim(),
},
success: function(html) {
var status = $.trim(html);
if (status) {
alert("Thanks for your submission");
$('#quick_contact')[0].reset();
return;
} else {
alert("Failed to submit.");
return false;
}
}
});
}
Then in your PHP, all you have to do is check if $_POST isset.
if (($_POST)) {
$status = 1; // init to one, assume there will not be an error
$name = $_POST['name'];
//etc, but FILTER the data coming from the client
}
Also, you may want to do something like this near your mail() function:
$success = mail(//etc);
if (!$success) {
$status = 0;
}
echo $status;
If you still have questions, let me know. I'm happy to help.
Related
First of all, I am kind of new with PHP and JavaScript. I am currently working on a contact form using MailHandler.php, TMForm.js and my contact.php file. I would like to know how can my message textarea show more than one validation error (for example, when some symbols are not validated lie #$<> and the min lenght is 5 characters, I want my textarea to show both validation errors one after another).
I added a RegExp at the end of my TMForm.js
regula.custom({
name:'Special'
,validator:function(){
return /^[^\$\%\&\|\<\>\#]*$/.test(this.value)
}
})
This is my contact.php textarea
<label class="message">
<textarea id="message" class="input" name="cf_message"
placeholder="Insert your message:"
data-constraints="#Required #Special #Length(min=5,max=999999)"></textarea>
<span class="empty-message">*This field is required.</span>
<span class="error-message">*The following characters are not allowed: $, %, &, |. <, > y #.</span>
and my MailHandler.php
<?php
session_start();
$count = 0;
if(isset($_POST['cf_email'])) {
$name = $_POST['cf_name'];
$email = $_POST['cf_email'];
$message = $_POST['cf_message'];
$email_to = "email#mail.com";
$email_subject = "You have a new email: ".$name;
$_SESSION['nameErr'] = $nameErr;
$count = $count + 1;
$_SESSION['emailErr'] = $emailErr;
$count = $count + 1;
$_SESSION['messageErr'] = $messageErr;
$count = $count + 1;
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message = "<html><body style='max-width: 800px;'>";
$email_message .= "<div><h1 style='font-weight: 500px; font-size: 2em; text-align: center; padding: 30px 0; border-bottom: 1px solid #1D547B; color: #2a3d51;' >El mensaje fue enviado por: ".clean_string($name)."\n</h1>";
$email_message .= "<p style='font-weight: 900px; font-size: 1em; text-align: justify; padding: 20px 0; font-style: italic; color: grey;'>".clean_string($message)."</p>";
$email_message .= "</div>";
$email_message .= "</body></html>";
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email_from."\r\n" .
'content-type: text/html; charset=ISO-8859-1\r\n'.
'X-Mailer: PHP/' . phpversion();
if ($count > 0) {
$Message = "The Message wasn not sent. Please verify again.";
$_SESSION['Message'] = $Message;
} else {
$Message = "You message was sent. Thank you.";
$_SESSION['Message'] = $Message;
#mail($email_to, $email_subject, $email_message, $headers);
}
$_SESSION['count'] = $count;
header("Location: ../contactenos.php");
}
?>
My question is if its possible to show both validation errors on their own and on the same textarea?
I suggest you to use more php to make things easy to return securely.
something like..
trim(stripslashes($_POST['cf_message']));
This way you can leave error handling for HTML/JS as you like with the UI...
so in the last 2 months my website is online, i have been received 2 normal email from my contact form and like 30 empty unfilled form emails. I also use validator http://faireware.de/js/jquery.form-validation-and-hints.js.
The weird is that i don't get these empty for emails when i i.e. dont fill an form and press send. It happens automaticly somehow... a spam bots or something, could it be?
My HTML code is:
<form method="post" action="contactengine.php">
<div class="field required">
<p>Name<br>
<input class="text verifyText hint" name="name" type="text" size="25" title="*Ihr Name..."></p>
</div><!--/field-->
<div class="field required ">
<p>E-Mail<br>
<input class="email verifyMail hint " name="email" type="text" size="25" title="*Ihre E-Mail-Adresse..."></p>
</div><!--/field-->
<div class="field required ">
<p>Nachricht<br>
<textarea name="message" rows="50" cols="50" title="*Schreiben Sie Ihre Nachricht..." class="hint "></textarea></p>
</div><!--/field-->
<p><input class="submit" type="submit" value="Senden"></p>
</form>
and my contactengine.php is:
<?php
$Subject = "Kontaktformular - FaireWare";
$Name = Trim(stripslashes($_POST['name']));
$Email = Trim(stripslashes($_POST['email']));
$Message = Trim(stripslashes($_POST['message']));
$EmailFrom = $Email;
$EmailTo = "info#faireware.de";
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n\n";
$Body .= "E-Mail: ";
$Body .= $Email;
$Body .= "\n\n";
$Body .= "Nachricht: ";
$Body .= "\n";
$Body .= $Message;
$Body .= "\n\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: $Email");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
And the empty email forms do come like this:
Name:
E-Mail:
Nachricht:
Does it do it automaticly and how can it surpass validation...? I don't know PHP and very little java, so does anyone have any idea where the problem could be?
Thank you!
You can try this, i have modified your code with basic server side validations.
<?
if(count($_POST) > 0)
{
$Subject = "Kontaktformular - FaireWare";
$Name = trim(stripslashes($_POST['name']));
$Email = trim(stripslashes($_POST['email']));
$Message = trim(stripslashes($_POST['message']));
$EmailTo = "info#faireware.de";
$validationOK = true;
if(empty($Name) || empty($Email) || empty($Message)){
$validationOK = false;
}
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
else
{
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n\n";
$Body .= "E-Mail: ";
$Body .= $Email;
$Body .= "\n\n";
$Body .= "Nachricht: ";
$Body .= "\n";
$Body .= $Message;
$Body .= "\n\n";
$headers = 'From: $Email' . "\r\n";
// send email
$success = mail($EmailTo, $Subject, $Body, $headers);
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
}
}
?>
What i have changed?
Add starting check if $_POST array not 0 and than add basic validation with empty(). If any one field empty email will not send else you will get the email.
Try to update your server-side code to unbreakable to avoid spam. Here is some suggestions.
Google Recaptcha
Honeypot Technique
Also do server side isset check.
if(isset($_POST['name'])){
// Save the data or do the further processing
}
Suggestion: Do not depend on client side validations when developing secure applications.
I am trying to update a column on my database. The user will click the confirm button and an email is sent to the user confirming a list of jobs and at the same time change the field status in column "confirmed" to "Yes".
I am able to send an email to the user but i have no clue as to why the column id like to update in my database doesn't work.
Here is my code
php:
<?php
ini_set("display_errors",1);
error_reporting(-1);
require("../controllers/cn.php");
include("/usr/share/php/Mail.php");
include("/usr/share/php/Mail/mime.php");
// Get the purchase order details
$query = mysql_query("SELECT Jobs.* FROM Jobs where job_status = 'Dispatched'") or die(mysql_error());
// Set the email content
$text = 'Text version of email';
$html .= '<html><body>';
$html .= '<p style="font-family: Arial, Helvetica, sans-serif; font-size: 22px; font-weight: bold; text-transform: uppercase; text-align: center;">Spineless Dispatch Summary</p>';
$html .= '<p style="font-family: Arial, Helvetica, sans-serif; font-size: 13px; text-align: center;">Please find below a summary of all dispatched orders: </p>';
$html .= '<table border="1" cellspacing="0" cellpadding="0" align="center"><tr><th width="200">Order Ref.</th><th width="200">First Name</th><th width="200">Last Name</th><th width="200">Tracking No.</th></tr>';
while($row = mysql_fetch_array($query)) {
$html .= '<tr>';
$html .= '<td style="padding: 10px;">'.$row['order_ref'].'</td>';
$html .= '<td style="padding: 10px;">'. $row['first_name'].'</td>';
$html .= '<td style="padding: 10px;">'.$row['last_name'].'</td>';
$html .= '<td style="padding: 10px;">'.$row['tracking_number'].'</td>';
$html .= '</tr>';
}
$html .= '</table></body></html>';
//$file = "/mnt/Jobs/Purchase_Orders/".date("Y", strtotime($row['created']))."/".date("F", strtotime($row['created']))."/PO".$row['id'].".pdf";
$crlf = "\n";
// Set customers email
$sendAddress = "rachelle#variouk.com";
// Set the from address
$hdrs = array(
'From' => 'rachelle#variouk.com',
'Subject' => 'Spineless System'
);
// Create the email
$mime = new Mail_mime(array('eol' => $crlf));
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
//$mime->addAttachment($file, 'application/pdf');
$body = $mime->get();
$hdrs = $mime->headers($hdrs);
// Send the email
$mail =& Mail::factory('mail');
// Paper company address
$mail->send($sendAddress, $hdrs, $body);
// Production email address (production#variouk.com)
$mail->send("rachelle#variouk.com", $hdrs, $body);
// Update the sent status of the order
$result = mysql_query("UPDATE Jobs SET confirmed = 'Yes' WHERE order_ref = '".$order_ref."' ");
header("location: joblist.php");
?>
HTML:
<div id="buttons" align="center">
<p style="padding-bottom: 15px; font-weight: bold; font-size: 14px;">Please confirm these jobs</p>
<button type="submit" class="btn btn-primary" onclick="javascript:window.location='email.php">Confirm</button>
<button class="btn btn-default btn-wide" onclick="javascript:window.location="'joblist.php'";>Cancel</button>
</div>
Edit2:
$order_refs = array();//array of orders to update in db.
while($row = mysql_fetch_array($query)) {
$html .= '<tr>';
$html .= '<td style="padding: 10px;">'.$row['order_ref'].'</td>';
$html .= '<td style="padding: 10px;">'. $row['first_name'].'</td>';
$html .= '<td style="padding: 10px;">'.$row['last_name'].'</td>';
$html .= '<td style="padding: 10px;">'.$row['tracking_number'].'</td>';
$html .= '</tr>';
$order_refs[]=$row['order_ref'];
}
And to update using ref from array
$result = mysql_query("UPDATE Jobs SET confirmed = 'Yes' WHERE order_ref IN ('". implode("', '", $order_refs) ."') ");
Let me know if it works.
Original:
Try adding
if(!$result){
echo mysql_error();
}
after
$result = mysql_query("UPDATE Jobs SET confirmed = 'Yes' WHERE order_ref = '".$order_ref."' ");
And tell me what does it say. I'll update my answer with a fix for that error. (I cannot comment on Questions yet, still low reputation)
Edit: as #Santik noted $order_ref is not defined in this code, so the fix would be to use $row['order_ref']
$result = mysql_query("UPDATE Jobs SET confirmed = 'Yes' WHERE order_ref = '".$row['order_ref']."' ");
I want to track my prospects from which URL(like fb, g+ or mailer) they have visited my website.This is all is for understanding visitor for better digital marketing.
My Fiddle: http://jsfiddle.net/dSp4g/
Please help me with code as below
Thanks in advance
HTML
<div class="form-group">
<label for="exampleInputEmail">Full name</label>
<input type="text" class="form-control " id="exampleInputName" placeholder="Enter your full name" style="color:#000 !important;">
</div>
<div class="form-group">
<input type="hidden" class="form-control " id="sourcecode">
</div>
<div class="form-group last">
<button class="mailbtn">Submit</button>
</div>
JS
$('.mailbtn').live('click',function(){
name = $('#exampleInputName').val();
sc = $('#sourcecode').val();
$(document).ready(function() {
if (sourcecode = $.parsequery().s)
{
$("#source").val(sourcecode); }
});
$.ajax({
type: "POST",
async : false,
url: "mail.php",
data: { name:name, sourcecode:sc}
})
.done(function( msg ) {
$('.mail_middle').html('');
$('.mail_middle').html('We will call you to confirm your delivery address.Thank you.');
return false;
});
});
mail.php
<?php
$to = array("my_email1","my_email2");
$message .= "<table border='1'>";
$message .= "<tr><td>Name </td><td>".$_POST['name']."</td></tr>";
$message .= "<tr><td>Source </td><td>".$_POST['sc']."</td></tr>";
$message .= "</table>";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= 'from: '.$from .'' . "\r\n" .
'Reply-To: '.$from.'' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
foreach($to as $row)
{
mail($row,$subject,$message,$headers);
}
echo "Mail Sent.";
die;
?>
Change $_POST['sc']
$message .= "<tr><td>Source </td><td>".$_POST['sc']."</td></tr>";
to $_POST['sourcecode']
$message .= "<tr><td>Source </td><td>".$_POST['sourcecode']."</td></tr>";
as sourcecode is the name (wheresc is the value)
data: { name:name, sourcecode:sc}
HTML
add a
<input type="hidden" name="the_ref" value="<?= $_SERVER['HTTP_REFERER']; ?>">
JS
modify to
data: { name:name, sourcecode:sc, the_ref:ref}
PHP
add a
$message .= "<tr><td>Visitor came from </td><td>".$_POST['the_ref']."</td></tr>";
your jquery implementation fails because in your php you are trying to read the $_POST['sc'] instead of $_POST['sourcecode']
I have tried a few different ways and am stuck with this. I have a form in a modal that slides out to order some parts. After you submit form it goes through a javascript test then post to a php page to send an email to company to order parts. I have it working except for two things. The radio buttons (three) are showing up unidentified and the "city" text is coming over empty. Here is the code and a link to page is http://arhcycles.com/new/drag-specialties.php
form
//declare our variables
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zipcode = $_POST['zipcode'];
$supplier1 = $_POST['supplier1'];
$supplier2 = $_POST['supplier2'];
$supplier3 = $_POST['supplier3'];
$supplier4 = $_POST['supplier4'];
$qty1 = $_POST['qty1'];
$qty2 = $_POST['qty2'];
$qty3 = $_POST['qty3'];
$qty4 = $_POST['qty4'];
$p_number1 = $_POST['p_number1'];
$p_number2 = $_POST['p_number2'];
$p_number3 = $_POST['p_number3'];
$p_number4 = $_POST['p_number4'];
$message = nl2br($_POST['message']);
//get todays date
$todayis = date("l, F j, Y, g:i a") ;
//set a title for the message
$subject = "Parts Order From ARH Cycles";
$body_message = '<html><body style="color:#FFFFFF; background-color: #850000">';
$body_message .= '<table border="1" bordercolor="#ffffff" cellpadding="10">';
$body_message .= '<tr style="background: #850000;"><td><strong>From:</strong> </td><td>'.$name.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Email:</strong> </td><td>'.$email.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Phone:</strong> </td><td>'.$phone.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Address:</strong> </td><td>'.$address .'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>City:</strong> </td><td>'.$city.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>State:</strong> </td><td>'.$state.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Zipcode:</strong> </td><td>'.$zipcode .'</td></tr>';
$body_message .= '</table>';
$body_message .= '<table border="1" bordercolor="#ffffff" cellpadding="10">';
$body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td>' .$supplier1.'</td><td><strong>Quanity:</strong> </td><td>'.$qty1.'</td><td><strong>Part Number:</strong></td><td>'.$p_number1.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td> ' .$supplier2.'</td><td><strong>Quanity:</strong> </td><td>'.$qty2.'</td><td><strong>Part Number:</strong></td><td>'.$p_number2.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td>' .$supplier3.'</td><td><strong>Quanity:</strong> </td><td>'.$qty3.'</td><td><strong>Part Number:</strong></td><td>'.$p_number3.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td>' .$supplier4 .'</td><td><strong>Quanity:</strong> </td><td>'.$qty4.'</td><td><strong>Part Number:</strong></td><td>'.$p_number4.'</td></tr>';
$body_message .= '</table>';
$body_message .= '<table border="1" bordercolor="#ffffff" cellpadding="10">';
$body_message .= '<tr style="background: #850000;"><td colspan="3"><strong>Message:</td></tr>';
$body_message .= '<tr style="background: #850000;"><td rowspan="3"colspan="3">' .$message .'</td></tr>';
$body_message .= '</table>';
$body_message .= '</body></html>';
$headers = "From: " .$email . "r\n" ;
$headers .= "Reply-To: ".$email . "\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
//put your email address here
mail("email#yourdomain.com, $email", $subject, $body_message, $headers);
?>
<!--Display a thankyou message in the callback -->
<div id="mail_response">
<h3>Thank you for your order <?php echo $name ?>!</h3><br />
<p>We will be calling to verify your order and take payment.</p><br />
<p>Please look over your order above and call (281) 970-1200 if incorrect.</p><br />
<h5>Message sent on: </h5>
<p><?php echo $todayis ?></p>
JavaScript
$(document).ready(function(){
//function for contact form dropdown
function contact() {
if ($("#contactForm").is(":hidden")){
$("#contactForm").slideDown("slow");
$("#backgroundPopup").css({"opacity": "0.7"});
$("#backgroundPopup").fadeIn("slow");
}
else{
$("#contactForm").slideUp("slow");
$("#backgroundPopup").fadeOut("slow");
}
}
//run contact form when any contact link is clicked
$(".contact").click(function(){contact()});
//animation for same page links #
$('a[href*=#]').each(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
&& location.hostname == this.hostname
&& this.hash.replace(/#/,'') ) {
var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
if ($(this.hash).length) {
$(this).click(function(event) {
var targetOffset = $(this.hash).offset().top;
var target = this.hash;
event.preventDefault();
$('html, body').animate({scrollTop: targetOffset}, 500);
return false;
});
}
}
});
//submission scripts
$('.contactForm').submit( function(){
//statements to validate the form
var filter = /^([a-zA-Z0-9_\.\-])+\#(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var email = document.getElementById('e-mail');
if (!filter.test(email.value)) {
$('.email-missing').show();
} else {$('.email-missing').hide();}
if (document.cform.name.value == "") {
$('.name-missing').show();
} else {$('.name-missing').hide();}
if (document.cform.message.value == "") {
$('.message-missing').show();
} else {$('.message-missing').hide();}
if ((document.cform.name.value == "") || (!filter.test(email.value)) || (document.cform.phone.value == "")){
return false;
}
if ((document.cform.name.value != "") && (filter.test(email.value)) && (document.cform.phone.value != "")) {
//hide the form
$('.contactForm').hide();
//show the loading bar
$('.loader').append($('.bar'));
$('.bar').css({display:'block'});
//send the ajax request
$.post('includes/mail.php',{name:$('#name').val(),
email:$('#e-mail').val(),
phone:$('#phone').val(),
address:$('#address').val(),
city:$('#city').val(),
state:$('#state').val(),
zipcode:$('#zipcode').val(),
supplier1:$('#supplier1').val(),
qty1:$('#qty1').val(),
p_number1:$('#p_number1').val(),
supplier2:$('#supplier2').val(),
qty2:$('#qty2').val(),
p_number2:$('#p_number2').val(),
supplier3:$('#supplier3').val(),
qty3:$('#qty3').val(),
p_number3:$('#p_number3').val(),
supplier4:$('#supplier4').val(),
qty4:$('#qty4').val(),
p_number4:$('#p_number4').val(),
message:$('#message').val()},
//return the data
function(data){
//hide the graphic
$('.bar').css({display:'none'});
$('.loader').append(data);
});
//waits 2000, then closes the form and fades out
setTimeout('$("#backgroundPopup").fadeOut("slow"); $("#contactForm").slideUp("slow")', 4000);
//stay on the page
return false;
}
});
//only need force for IE6
$("#backgroundPopup").css({
"height": document.documentElement.clientHeight
});
});
php
<?php
//declare our variables
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zipcode = $_POST['zipcode'];
$supplier1 = $_POST['supplier1'];
$supplier2 = $_POST['supplier2'];
$supplier3 = $_POST['supplier3'];
$supplier4 = $_POST['supplier4'];
$qty1 = $_POST['qty1'];
$qty2 = $_POST['qty2'];
$qty3 = $_POST['qty3'];
$qty4 = $_POST['qty4'];
$p_number1 = $_POST['p_number1'];
$p_number2 = $_POST['p_number2'];
$p_number3 = $_POST['p_number3'];
$p_number4 = $_POST['p_number4'];
$message = nl2br($_POST['message']);
//get todays date
$todayis = date("l, F j, Y, g:i a") ;
//set a title for the message
$subject = "Parts Order From ARH Cycles";
$body_message = '<html><body style="color:#FFFFFF; background-color: #850000">';
$body_message .= '<table border="1" bordercolor="#ffffff" cellpadding="10">';
$body_message .= '<tr style="background: #850000;"><td><strong>From:</strong> </td><td>'.$name.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Email:</strong> </td><td>'.$email.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Phone:</strong> </td><td>'.$phone.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Address:</strong> </td><td>'.$address .'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>City:</strong> </td><td>'.$city.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>State:</strong> </td><td>'.$state.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Zipcode:</strong> </td><td>'.$zipcode .'</td></tr>';
$body_message .= '</table>';
$body_message .= '<table border="1" bordercolor="#ffffff" cellpadding="10">';
$body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td>' .$supplier1.'</td><td><strong>Quanity:</strong> </td><td>'.$qty1.'</td><td><strong>Part Number:</strong></td><td>'.$p_number1.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td> ' .$supplier2.'</td><td><strong>Quanity:</strong> </td><td>'.$qty2.'</td><td><strong>Part Number:</strong></td><td>'.$p_number2.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td>' .$supplier3.'</td><td><strong>Quanity:</strong> </td><td>'.$qty3.'</td><td><strong>Part Number:</strong></td><td>'.$p_number3.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td>' .$supplier4 .'</td><td><strong>Quanity:</strong> </td><td>'.$qty4.'</td><td><strong>Part Number:</strong></td><td>'.$p_number4.'</td></tr>';
$body_message .= '</table>';
$body_message .= '<table border="1" bordercolor="#ffffff" cellpadding="10">';
$body_message .= '<tr style="background: #850000;"><td colspan="3"><strong>Message:</td></tr>';
$body_message .= '<tr style="background: #850000;"><td rowspan="3"colspan="3">' .$message .'</td></tr>';
$body_message .= '</table>';
$body_message .= '</body></html>';
$headers = "From: " .$email . "r\n" ;
$headers .= "Reply-To: ".$email . "\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
//put your email address here
mail("email#yourdomain.com, $email", $subject, $body_message, $headers);
?>
<!--Display a thankyou message in the callback -->
<div id="mail_response">
<h3>Thank you for your order <?php echo $name ?>!</h3><br />
<p>We will be calling to verify your order and take payment.</p><br />
<p>Please look over your order above and call (281) 970-1200 if incorrect.</p><br />
<h5>Message sent on: </h5>
<p><?php echo $todayis ?></p>
</div>