Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cron job won't open file_get_contents

i'm running a php script that uses file_get_contents in order to mail a list with what it's inside that remote file. If i run the script manually everything works fine, but when i leave it and wait for the cron to run it doesn't get that remote content..... Is that possible? i copy here a bit of the code where i think the problem is:

$flyer = file_get_contents('flyer.html');

$desti = $firstname." ".$lastname;

$mail = new phpmailer();

$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "orion.xxxx.com"; // line to be changed
$mail->Port = 465; // line to be changed
$mail->Username = '[email protected]'; // line to be changed
$mail->Password = 'xxxx90'; // line to be changed
$mail->FromName = 'Bob'; // line to be changed
$mail->From = '[email protected]';// line to be changed

$mail->AddAddress($email, $desti);

$mail->Subject = 'The Gift Store';    // to be changed



if ($cover_form == '1'){ $mail->MsgHTML($long10);} else
if ($cover_form == '2'){ $mail->MsgHTML($customer);} else
if ($cover_form == '3'){ $mail->MsgHTML($freedoers);} else
if ($cover_form == '4'){ $mail->MsgHTML($freelongform);}  else
if ($cover_form == '5'){ $mail->MsgHTML($freestoreshort);}  else
if ($cover_form == '6'){ $mail->MsgHTML($getasiteshort);}  else
if ($cover_form == '7'){ $mail->MsgHTML($flyer);}  
else {}
like image 550
Sebastian Avatar asked Feb 11 '12 15:02

Sebastian


2 Answers

The cron doesn't load the code from the 'folder' you are in, so you will need to specify a full path

$flyer = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . "flyer.html");

like image 109
Richard Avatar answered Sep 19 '22 05:09

Richard


The path of the file is different when the cron executes

Try

$flyer = file_get_contents(__DIR__ . '/flyer.html');

Or specify the path yourself

like image 23
remy Avatar answered Sep 19 '22 05:09

remy