cron 作业不会打开 file_get_contents
我正在运行一个使用 file_get_contents 的 php 脚本,以便通过邮件发送包含远程文件内内容的列表。 如果我手动运行脚本,一切正常,但是当我离开它并等待 cron 运行时,它不会获取远程内容......这可能吗? 我在这里复制了一些我认为问题所在的代码:
$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 {}
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 {}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
cron 不会从您所在的“文件夹”加载代码,因此您需要指定完整路径
$flyer = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . "flyer.html");
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");
cron 执行时文件的路径不同
尝试
$flyer = file_get_contents(__DIR__ . '/flyer.html');
或者自己指定路径
The path of the file is different when the cron executes
Try
$flyer = file_get_contents(__DIR__ . '/flyer.html');
Or specify the path yourself
尝试这样:
try like this:
您应该确保输出和错误被重定向到一个文件,这样您就可以了解 cron 运行时脚本的情况。
crontab 中的命令如下所示:
不过,看看您的代码,我建议您使用绝对路径来打开
flyer.html
文件,这样即使从包含该文件的另一个目录启动,您的脚本也能正常工作。You should make sure that the output and errors get redirected to a file, so you can get an idea of what's going on with your script when run by cron.
The command in the crontab would look like this :
Looking at your code, though, I would suggest you use an absolute path to open the
flyer.html
file, so your script works even if launched from another directory that the one containing that file.