我只需要在未来发送one电子邮件,所以我想我最好使用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>输出应该类似于
警告:将使用/bin/sh执行命令
工作60在清华12月30日19:39:00 2010
然而,我做了什么错误的主管,但没有得到结果?
最重要的是这看起来很混乱。有没有其他更好的方法来做这件事?
PS:我不得不将apache的用户(www-data )添加到/etc/ it。允许我不喜欢的...Which,但我可以接受它。
发布于 2010-12-31 01:11:15
你基本上在做
mail | at它会将邮件的输出输送到at命令。这是错误的。邮件命令将立即执行,输出(通常没有,除非有警告)将被安排在您指定的任何时间运行。
您的脚本应该将邮件命令转储到文件中,然后对
at whenver < mailcmd.shhttps://stackoverflow.com/questions/4567345
复制相似问题