I am now to this altogether. I need the success message when the lightbox contact form is posted to appear in the lightbox. The mail is not sent out neither is the success message displayed.
I have the following code in my site to collect the data and post it to a separate page that send out mail. The thing is email is not sent out using the mail.php file. Need help.
<script>
function sendEmail() {
// 1. Create XHR instance - Start
var xhr;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
}
else {
throw new Error("Form is not supported by this browser");
}
// 1. Create XHR instance - End
// 2. Define what to do when XHR feed you the response from the server - Start
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status == 200 && xhr.status < 300) {
// document.getElementById('loadix').innerHTML = xhr.responseText;
if(xhr.responseText == "success"){
$('#confirmation').html("<h2><i>Thank you for Registering for the webinar. An email with a link to the webinar will be emailed to you soon.</i></h2>");
$('#tosend').val(0);
}
else {
$('#confirmation').html("<h2>Email sending failed</h2>");
}
}
}
}
// 2. Define what to do when XHR feed you the response from the server - Start
var message = document.getElementById("message").value;
var subject = document.getElementById("subject").value;
var email = document.getElementById("email").value;
var Home_phone = document.getElementById("Home_phone").value;
var full_name = document.getElementById("full_name").value;
var day = document.getElementById("day").value;
var tosend = document.getElementById("tosend").value;
var post_str = "&message=" + message +"&subject=" + subject +"&email=" + email +"&Home_phone=" + Home_phone +"&full_name=" + full_name +"&day=" + day;
// 3. Specify your action, location and Send to the server - Start
if(tosend == 1){
xhr.open('POST', 'mail.php');
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(post_str);
}
// 3. Specify your action, location and Send to the server - End
return true;
}
The mail.php has the following code.
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "[email protected]";
$full_name = $_POST['full_name']; // required
$day = $_POST['day']; // required
$email_from = $_POST['email']; // required
$Home_phone = $_POST['Home_phone']; // not required
$subject = $_POST['subject']; // required
$message = $_POST['message']; // required
$email_message = "Webinar request details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Message: ".clean_string($message)."\n";
$email_message .= "Name: ".clean_string($full_name)."\n";
$email_message .= "Home_phone: ".clean_string($Home_phone)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Day: ".clean_string($day)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
}
?>