将来的には1通のメールを送信する必要があるので、を使用at
するよりも使用するのが最善だと思いましcron
た。これは私がこれまでに持っているものであり、その厄介で醜いものであり、逃げるのはそれほど得意ではありません:
<pre>
<?php
$out = array();
// Where is the email going?
$email = "you@gmail.com";
// What is the body of the email (make sure to escape any double-quotes)
$body = "This is what is actually emailed to me";
$body = escapeshellcmd($body);
$body = str_replace('!', '\!', $body);
// What is the subject of the email (make sure to escape any double-quotes)
$subject = "It's alive!";
$subject = escapeshellcmd($subject);
$subject = str_replace('!', '\!', $subject);
// How long from now should this email be sent? IE: 1 minute, 32 days, 1 month 2 days.
$when = "1 minute";
$command= <<<END
echo "
echo \"$body\" > /tmp/email;
mail -s \"$subject\" $email < /tmp/email;
rm /tmp/email;
" | at now + $when;
END;
$ret = exec($command, $out);
print_r($out);
?>
</pre>
出力は次のようになります
警告:コマンドは、 2010年12月30日木曜日19:39:00に/ bin/shジョブ60を使用して実行されます。
しかし、私はexecで何か間違ったことをしていて、結果が得られませんか?
主なことは、これは非常に厄介に見えるということです。これを行うための代替のより良い方法はありますか?
PS:apacheのユーザー(私にとってはwww-data)を/etc/at.allowに追加する必要がありました...これは好きではありませんが、一緒に暮らすことができます。