gpt4 book ai didi

php - 通过 jQuery/PHP 发送电子邮件

转载 作者:行者123 更新时间:2023-12-01 03:57:00 26 4
gpt4 key购买 nike

如果用户提出问题,如何通过 jQuery 和 PHP 发送电子邮件?

我的 JS 代码在 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.");
});

它的处理程序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>"
);

最佳答案

您可能没有邮件服务器!当您在计算机上使用 LocalHost 时,通常会发生这种情况。

关于php - 通过 jQuery/PHP 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1317615/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com