Creating PHP Mailer Script based on AJAX/js coding

Hey guys,

I have the following javascript/AJAX coding for my contact form, but I can’t find the email.php file that I received for the contact form and I can’t redownload the package. If someone here could help me construct the mailer script, then it would be much appreciated.

[code]$(function() {
$("#contact_button").click(function() {
var contact_name = $("#contact_name").val();
var contact_email = $("#contact_email").val();
var contact_subject = $("#contact_subject").val();
var contact_text = $("#contact_text").val();
var emailReg = /^([a-zA-Z0-9_.-+])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
var dataString = ‘&name=’+ contact_name + ‘&email=’ + contact_email + ‘&text=’ + contact_text + ‘&subject=’ + contact_subject;
var go = true;
var emailcheck = false;

$(’.name-error’).removeClass(‘error-display’);
$(’.email-error’).removeClass(‘error-display’);
$(’.topic-error’).removeClass(‘error-display’);
$(’.message-error’).removeClass(‘error-display’);
$(’.submit-wrapper’).find(’#contact_button’).attr(‘value’,‘Send Email’);
$(’#contact_button’).removeClass(‘skin-contact-done’);

if(contact_name==‘Name’){
$(’.name-error’).addClass(‘error-display’);
go=false;
}

if(contact_name==’’){
$(’.name-error’).addClass(‘error-display’);
go=false;
}

if(contact_email==‘Email’){
$(’.email-error’).addClass(‘error-display’);
go=false;
}

if(contact_email==’’){
$(’.email-error’).addClass(‘error-display’);
go=false;
}
else{
if(emailReg.test(contact_email)){
emailcheck = true;
}
else {
$(’.email-error’).addClass(‘error-display’);
go=false;
}
}

if(contact_subject==‘Subject’){
$(’.topic-error’).addClass(‘error-display’);
go=false;
}

if(contact_subject==’’){
$(’.topic-error’).addClass(‘error-display’);
go=false;
}

if(contact_text==‘Email content’){
$(’.message-error’).addClass(‘error-display’);
go=false;
}

if(contact_text==’’){
$(’.message-error’).addClass(‘error-display’);
go=false;
}

if ( go == false){
return false;
}

$.ajax({
type: “POST”,
url: “email.php”,
data: dataString,
success: function(){
$(’.submit-wrapper’).find(’#contact_button’).attr(‘value’,‘Thank you!’);
$(’#contact_button’).addClass(‘skin-contact-done’);
}
});
$(’.contact’).find(‘form’)[0].reset();
return false;
});
});[/code]

That’s done a little backwards. I wouldn’t build the data string until after all the validation is done. but to answer the question, look at datastring. for each item in there, you need a corresponding $_POST in email.php. from there, its just like any other email script, there’s plenty of tutorials out there for that.

I realize it’s backwards. I downloaded the template a few months ago and I have already customized it completely. However, I just realized that the email.php file wasn’t included, or I deleted it by mistake, and now I can’t find where I downloaded the free template from.

I’m not an experienced coder, so I’m looking for some assistance or guidance. Do you have a tutorial site that you would recommend?

Sponsor our Newsletter | Privacy Policy | Terms of Service