title: CRON - PHP - file_get_contents to run PHP page and email with CRON
body: <p>I am trying to setup an end-of-day automated email using a CRON job.</p>
  
  <p>I can get the CRON job to send out a static email, however I am having trouble when trying to use file_get_contents and a php page that then uses mysql queries to get the data from a database and builds the email body.</p>
  
  <p>Need help!
  *NOTE- I use a special php mailer for SMTP. This mailer works 100% FINE when sending any static email or sending dynamic emails manually (not CRON).
  Just having trouble getting the CRON job to actually access the PHP file and get the data.</p>
  
  <p>Mailer file being run by CRON:</p>
  
  <pre><code>#!/usr/bin/php
  &lt;?php
  set_include_path('/Library/WebServer/Documents/pbhsadmin/');
  include '_classes/class.phpmailer.php';
  
      $email = 'EMAIL';
  try {
      $mail = new PHPMailer(true); //New instance, with exceptions enabled
  
      $mail-&gt;Subject  = "PBHS Administration - Changes Department Daily Report";  
      $body = file_get_contents('http://localhost/pbhsadmin/_mail/changes_daily.php');
      //$body = 'Testing no get file';
      $body = preg_replace('/\\\\/','', $body); //Strip backslashes
  
      $mail-&gt;From       = "support@pbhs.uservoice.com";
      $mail-&gt;FromName   = "PBHS Support";
      $mail-&gt;IsSMTP();                           // tell the class to use SMTP
      $mail-&gt;SMTPAuth   = true;                  // enable SMTP authentication
      $mail-&gt;Port       = 25;                    // set the SMTP server port
      $mail-&gt;Host       = "mail.SERVER.com"; // SMTP server
      $mail-&gt;Username   = "EMAIL"     // SMTP server username
      $mail-&gt;Password   = "PASSWORD";            // SMTP server password
  
      $mail-&gt;IsSendmail();  // tell the class to use Sendmail
  
      $mail-&gt;AddReplyTo("support@pbhs.uservoice.com","PBHS Support");     
  
      $mail-&gt;AddAddress($email);
  
      $mail-&gt;AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
      $mail-&gt;WordWrap   = 80; // set word wrap
  
      $mail-&gt;MsgHTML($body);
  
      $mail-&gt;IsHTML(true); // send as HTML
  
      $mail-&gt;Send();
      echo 'message sent!';
  } catch (phpmailerException $e) {
      echo $e-&gt;errorMessage();
  }
  ?&gt;
  </code></pre>
  
  <p>PHP Page using mysql to query database and create email:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
  &lt;title&gt;Changes Department - Daily Report&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?PHP
  set_include_path('/Library/WebServer/Documents/pbhsadmin/');
  include 'SQL CONNECTION FILE';
  
  $query = "QUERY";
  $result = mysql_query($query)or die(mysql_error());
  while($row=mysql_fetch_array($result)){
      if($row['userid']==0)
          $username = 'Unassigned';
      else        
          $username = $row['username'];
      $userid = $row['userid'];
      //GET ALL PROJECTS WORKED ON FOR THIS USER
      $query2 = "QUERY";
      $result2 = mysql_query($query2)or die(mysql_error());
  echo '
  &lt;div class="employee"&gt;
  &lt;h1&gt;'.$username.'&lt;/h1&gt;
  &lt;table&gt;&lt;tr&gt;&lt;th&gt;Site&lt;/th&gt;&lt;th&gt;Hours Worked&lt;/th&gt;&lt;th&gt;Total Hours&lt;/th&gt;&lt;th&gt;Status&lt;/th&gt;&lt;/tr&gt;';
      while($row2=mysql_fetch_array($result2)){
  
          $domain = $row2['domain'];
          $hours = $row2['hours'];
          if($row2['completed']!='0000-00-00 00:00:00')
              $status = 'Completed';
          else
              $status = 'Incomplete';
          $total_hours = $row2['act_hours'];
  
          echo '&lt;tr&gt;&lt;td class="center"&gt;'.$domain.'&lt;/td&gt;&lt;td class="center"&gt;'.$hours.'&lt;/td&gt;&lt;td class="center"&gt;'.$total_hours.'&lt;/td&gt;&lt;td class="center '.$status.'"&gt;'.$status.'&lt;/td&gt;&lt;/tr&gt;';
      }
      if(mysql_num_rows($result2)==0)
          echo '&lt;tr&gt;&lt;td colspan="4" style="text-align:center;"&gt;&lt;i&gt;No Projects Worked On&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;';
  echo '&lt;/table&gt;&lt;/div&gt;';
  }
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>