Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Thanked 0 Times in 0 Posts

    Ajax code to send values to a php file.

    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

    PHP Code:

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

    mail($admin_emailYou have a new comment", $message);
    what could be wrong and is there anyone that knows how to fix this to make it work?

  • #2
    New to the CF scene
    Join Date
    Dec 2011
    Thanked 0 Times in 0 Posts
    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);


    LinkBacks (?)

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts