【发布时间】:2010-11-22 00:04:04
【问题描述】:
如果用户提出问题,如何通过 jQuery 和 PHP 发送电子邮件?
我在 HEAD 中的 JS 代码
jQuery('a.flag_question').live('click', function(){
jQuery.post('/codes/handlers/flag_question.php',
{ question_id: jQuery(this).attr('rel') });
alert ("Question was reported.");
});
它的处理程序 flag_question.php 不会向我发送电子邮件
$question_id = $_POST['question_id']; // data from jQuery.post
$subject = "Flagged question";
$to = '"Michael Boltman <michael.boltman777@gmail.com>';
$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!");
}
我确实使用了我的真实电子邮件地址,而代码中的那个是伪地址。
链接由PHP生成
echo ("<a href='#'"
. " class='flag_question'"
. " rel='" . $question_id . "'>flag</a>"
);
【问题讨论】: