title: PHP variable from external file?
body: <p><strong>*EDIT / FINISHED SOLUTION / WORKING CODE</strong></p>
  
  <p>So, this is what a friend of mine helped me come up with.</p>
  
  <p>Here is the part I use in my K2 "items.php" file:</p>
  
  <pre><code>&lt;div class="fb-comments" data-href="&lt;?php echo JURI::current(); ?&gt;" data-num-posts="8" notify="true" data-width="580"&gt;&lt;/div&gt;
  
  &lt;input id="authname" style="display: none;" type="text" value="&lt;?php echo $this-&gt;item-&gt;author-&gt;name; ?&gt;" /&gt;
  &lt;input id="authmail" style="display: none;" type="text" value="&lt;?php echo $this-&gt;item-&gt;author-&gt;email; ?&gt;" /&gt;
  &lt;input id="link" style="display: none;" type="text" value="&lt;?php echo JURI::current(); ?&gt;" /&gt;
  
  &lt;script&gt;
  window.fbAsyncInit = function() {
  FB.Event.subscribe('comment.create', function (response) {
  
      var commentQuery = FB.Data.query("SELECT text, fromid FROM comment WHERE post_fbid='" + response.commentID +
      "' AND object_id IN (SELECT comments_fbid FROM link_stat WHERE url='" + response.href + "')");
      var userQuery = FB.Data.query("SELECT name FROM user WHERE uid in (select fromid from {0})", commentQuery);
  
          FB.Data.waitOn([commentQuery, userQuery], function () {
              var commentRow = commentQuery.value[0];
              var userRow = userQuery.value[0];
              console.log(userRow.name + " (id: " + commentRow.fromid + ") posted the comment: " + commentRow.text);
              trackcomments(response['commentID'], response['href'], 'create', commentRow.text, userRow.name, commentRow.fromid);
          });
      });
  };
  
  function trackcomments(_commentid, _address, _action, _commentMessage, _userName, _userId) {
      var authname = document.getElementById('authname').value;
      var authmail = document.getElementById('authmail').value;
      var link = document.getElementById('link').value;
  
      $.ajax({
          type: 'POST',
          url: 'http://mydomain.com/dostuff.php', 
          data: {'commentMessage': _commentMessage, 'userName': _userName, 'authname': authname, 'authmail': authmail, 'link': link},
          cache: false
      });
  
  };
  &lt;/script&gt;
  </code></pre>
  
  <p>And this is the do_stuff.php:</p>
  
  <pre><code>&lt;?php
  
      //Handle some weird letters and stuff
      setlocale(LC_TIME, 'swedish'); 
  
      //creating an $author variable and populating it from $_POST
      $author = $_POST['authname'];
      $authoremail = $_POST['authmail'];
      $link = $_POST['link'];
      $commentMessage = $_POST['commentMessage'];
      $userName = $_POST['userName'];
  
      $date = strftime('%A %e %b %Y %H.%M', time());
  
      //getting author email
      $to = $authoremail;
  
      //subject of email      
      $subject = "New comment posted on mydmomain.com";
  
      //email content
      $message = "On $date $userName wrote\n\n$commentMessage\n\non your entry $link#comments\n\nUse the above link to answer on the comment.";
  
      //who the mail is from
      $from = "admin@mydomain.com";
  
      //header
      $headers = "From:" . $from;
  
      //send the email
      mail($to,$subject,$message,$headers);
  ?&gt;
  </code></pre>
  
  <p>Turns out, there was a simple reason it wasn't working... JavaScript doesn't seem to handle PHP!</p>
  
  <p>So the "do_stuff.php" (earlier named sendmail.php) was never executed with the echo JURI::base();.</p>
  
  <p>Even then though. The var = $this->item... was also trying to get data from PHP variables which wasn't working. So, to combat that the values of those variables where put in hidden input forms to retrieve them thru getObjectById.</p>
  
  <p>Like my friend stated, don't know if this is the most elegant or sophisticated solution... but it does the trick and fills it's purpose.</p>
  
  <p>However, if someone has a better more "correct" way of achieving this, I'm all ears  :)</p>
  
  <p>Thank you @jack for your help! And anyone else contributing to this subject in the future.</p>
  
  <p><strong>- ORIGINAL POST -</strong></p>
  
  <p>Still learning about PHP and Joomla and K2. Been sitting upp for days now trying to figure out how I can have specific authors receive emails when comments are made using fb:comments.</p>
  
  <p>So far so good...
  <a href="https://stackoverflow.com/questions/14988508/fb-event-subscribe-comment-create-acting-without-action-from-user">FB.event.subscribe comment.create acting without action from user</a></p>
  
  <p>Now, the only thing missing is the referens to the variable "$item->author->name". Since this is usable in the original file (item.php) where I'm calling for the sendmail.php</p>
  
  <pre><code>&lt;script&gt;
  window.fbAsyncInit = function() {
  
      /* All the events registered */
      FB.Event.subscribe('comment.create', function (response) {
          $.get('&lt;?php echo JURI::base(); ?&gt;sendmail.php');
      });
  };
  &lt;/script&gt;
  </code></pre>
  
  <p>and this is the "sendmail.php" file</p>
  
  <pre><code>&lt;?php
      if ($item-&gt;author-&gt;name == "Firstname1 Lastname1"){
          $to = "author1@mydomain.com";
      }else if ($item-&gt;author-&gt;name == "Firstname2 Lastname2"){
          $to = "author2@mydomain.com";
      };
  
      $subject = "New comment";
      $message = "A new comments has been made.";
      $from = "admin@mydomain.com";
      $headers = "From:" . $from;
      mail($to,$subject,$message,$headers);
  ?&gt;
  </code></pre>
  
  <p>I don't know how I can get the $item->author->name to work. Since I need to make sure that it somehow checks to see what the name is (since it's showing on the generated page I have to be able to use it somehow) to specify which email to send TO.</p>
  
  <p>I have no idea if this has already been asked, but I don't even know what to search for to get me started here. I can't imagine that this would be to difficult to solve (if you only know what you need to change). :)</p>