我有一個名爲「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