How can you send an email by jQuery and PHP if the user flags a question?
My JS code in HEAD
jQuery('a.flag_question').live('click', function(){
jQuery.post('/codes/handlers/flag_question.php',
{ question_id: jQuery(this).attr('rel') });
alert ("Question was reported.");
});
Its handler flag_question.php which does not send me an email
$question_id = $_POST['question_id']; // data from jQuery.post
$subject = "Flagged question";
$to = '"Michael Boltman <[email protected]>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message = "<a href='index.php?question_id=" . $question_id . "'>"
. "The question " . $question_id . "</a> is flagged by an user. Please, review it.";
if ( mail( $to, $subject, $message ) ) {
echo ("Thank you for your report!");
}
I did use my real email address, while the one in the code is pseudo one.
The link is generated by PHP
echo ("<a href='#'"
. " class='flag_question'"
. " rel='" . $question_id . "'>flag</a>"
);