好的,这就是我的问题。我试图在 Facebook 评论中发表评论后向个别帖子的作者发送一封电子邮件(以通知作者已发表评论)。评论框位于 K2 项目中(在 Joomla 中)。
FB.event.subscribe comment.create 正在工作,我已经尝试过
警报('解雇');
效果很好。但是当我输入 PHP 时,它只是开始向每次有人进入该页面时给出的第一封电子邮件发送电子邮件。如何让它仅在创建或添加评论时发送电子邮件?
<script>
window.fbAsyncInit = function(){
FB.Event.subscribe('comment.create', function(response){
<?php
if ($this->item->author->name = 'Author1'){
$to = "[email protected] /cdn-cgi/l/email-protection";
}else if ($this->item->author->name = 'author2'){
$to = "[email protected] /cdn-cgi/l/email-protection";
};
$subject = "Test mail";
$message = "Hello! This is a simple email message. live run";
$from = "[email protected] /cdn-cgi/l/email-protection";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
?>;
});
};
</script>
EDIT请点击此链接来自外部文件的 PHP 变量? https://stackoverflow.com/questions/14992143/php-variable-from-external-file关于这个主题的完整解决方案以及我在这里试图完成的任务。
PHP 被执行服务器端。当回调被触发时,PHP 已经执行(当页面被请求时)。
相反,您需要在 PHP 脚本的回调中进行 AJAX 调用,该脚本将执行您需要执行的任何操作:
window.fbAsyncInit = function(){
FB.Event.subscribe('comment.create', function(response){
$.post('/sendemail.php');
});
};
将其余代码放入sendemail.php
这假设您正在使用 jQuery。
Note:这是一个非常糟糕的主意,因为在没有任何验证的情况下,用户可以只是向sendemail.php
并从某人的邮箱中发送垃圾邮件。考虑安全性、速率限制等。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)