<input type="image" id="imageField" class="btn" src="<?php bloginfo('template_url'); ?>/media/global/btn-go.gif" onclick = "sendRequestPost(document.getElementById('email1').value);" />
The function sendRequestPost() is in a file named header.php:
// Set path to PHP script
var phpscript = 'subscribe.php';
function sendRequestPost(data) {
// Open PHP script for requests
MM_validateForm('email1','','RisEmail');
if (document.MM_returnValue) {
<?php
$email = ??????????????????????????????????
$subject = 'The Second Floor: Test 000 Welcome!';
$message = 'Greetings!'. "\r\n\r\n";
$message .= 'Thank you for signing up for updates via the T2F website. We will keep you posted on events, new coffee concoctions, and fresh book titles.'. "\r\n\r\n";
$message .= 'We look forward to seeing you soon.'. "\r\n\r\n";
$message .= 'Peace!'. "\r\n";
$message .= 'Sabeen'. "\r\n\r\n";
$message .= 'http://www.t2f.biz'. "\r\n";
$message .= 'http://www.t2f.biz/t2f-events'. "\r\n";
$message .= 'http://www.t2f.biz/blog';
$headers = 'From: Sabeen Mahmud <example@example.com>'. "\n";
$headers .= 'Bcc: example2@example.com';
mail($email, $subject, $message, $headers);
?>
http.open('post', phpscript);
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http.onreadystatechange = handleResponsePost;
http.send('email1='+data);
}
}
The file subscribe.php is as under:
<?php
/ Short and sweet /
if (! isset($wp_did_header)):
$wp_did_header = true;
require_once( dirname(FILE) . '/wp-config.php');
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
global $wpdb;
if(isset($POST['email1'])){
$email = $POST['email1'];
$query2 = "SELECT * FROM rs_em WHERE EMAIL = '".$email."'";
$found = $wpdb->get_var($query2);
if (!$found) {
//<div id="message" class="success"></div>
echo("<div id=\"message\" class=\"success\">Thank you! We will keep you posted.</div>");
/
$subject = 'The Second Floor: Test 000 Welcome!';
$message = 'Greetings!'. "\r\n\r\n";
$message .= 'Thank you for signing up for updates via the T2F website. We will keep you posted on events, new coffee concoctions, and fresh book titles.'. "\r\n\r\n";
$message .= 'We look forward to seeing you soon.'. "\r\n\r\n";
$message .= 'Peace!'. "\r\n";
$message .= 'Sabeen'. "\r\n\r\n";
$message .= 'http://www.t2f.biz'. "\r\n";
$message .= 'http://www.t2f.biz/t2f-events'. "\r\n";
$message .= 'http://www.t2f.biz/blog';
$headers = 'From: Sabeen Mahmud <example@example.com>'. "\n";
$headers .= 'Bcc: example2@example.com';
mail($email, $subject, $message, $headers);
/
$query = "INSERT INTO rs_em (email) VALUES ('".$email."')";
$wpdb->query($query);
} else {
// <div id="message" class="error"></dib>
echo("<div id=\"message\" class=\"error\">Ooops. We already have this <nobr>e-mail</nobr> address in our database. Please enter another address.</div>");
}
}
endif;
?>
Actually the Ajax message come after 8 to 9 seconds here and the same PHP mail function takes only 1.5 to 2 seconds when written in header.php but how can I use the email from $_POST here?
Please help me, this is my first task as a web developer for the website (www.t2f.biz). How can I use the argument value of the function to send email. Thx