我有一个名为“basic.txt”具有以下文本的文本文件mail()函数将无法识别消息变量是在PHP的cronjob
This
is a
test file.
我的cronjob运行我的PHP程序每分钟向我发送一封电子邮件。我收到的电子邮件没有问题,但不包含正文消息。这是我的PHP代码:
<?php
$string = "";
$file = fopen("basic.txt", "r");
$string .= file_get_contents("basic.txt");
$fclose($file);
echo $string; // this is to test that in fact $string contains the text and it does
mail("examp[email protected]", "TEST", $string, "From: [email protected]");
?>
为什么不是$字符串发送从文本文件中的文本,即使我可以用电子邮件的正文“回声$字符串”,它工作正常?
感谢
你可以试试'$ string。= file_get_contents($ file);'和/或把你的'$ fclose($ file);'发送邮件后。似乎你可能会很快关闭文件。也检查文件权限。 –
$ string。= file_get_contents($ file);不起作用,它说我需要在那里有文件名。 $ FCLOSE($文件);在邮件功能不起作用之后。 – Michael
'file_get_contents()'不需要'fopen()',因此''fclose()'也不需要 – RiggsFolly