View Full Version : Ajax code to send values to a php file.

01-05-2012, 11:59 AM
How come the below code is not woring for me? when someone comments on my facebook comments plugin I want to get an email.

This is what i have

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<div id="fb-root"></div>
<script> window.fbAsyncInit = function() {

appId : '220041184732123', // App ID
channelUrl : '//http://www.corkdiscos.com/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML

FB.subscribe('comment.create', function(response){
// Here you need to do a call to some service/script/application
// to notify your administrator about new comment.
// I'll use jQuery ajax to call server-side script to illustrate the flow
$.post('mail.php', {
"action": "comment created",
"url_of_page_comment_leaved_on": response.href,
"id_of_comment_object": response.commentID


// Load the SDK Asynchronously
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";

<div class="fb-comments" notify="true" data-href="http://www.corkdiscos.com/testimonials.html" data-num-posts="30" data-width="544"></div>

I then have this php code to send me a mail in a mail.php file

$admin_email = 'corkdjs@gmail.com';

$commentID = $_REQUEST['id_of_comment_object'];
$page_href = $_REQUEST['url_of_page_comment_leaved_on'];
$message = "hello";

mail($admin_email, 'You have a new comment", $message);

what could be wrong and is there anyone that knows how to fix this to make it work?

01-05-2012, 08:36 PM
You have one quote instead of two on line 8. You have:
mail($admin_email, You have a new comment", $message);

You might want to create a $subject variable and try this method instead:
mail($admin_email, $subject, $message);