【发布时间】:2016-05-11 21:25:58
【问题描述】:
我有一个名为“basic.txt”的文本文件,其中包含以下文本
这个
是一个
测试文件。
我的 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("example@hotmail.com", "TEST", $string, "From: example@hotmail.com");
?>
即使我可以使用“echo $string”并且它工作正常,为什么 $string 不将文本文件中的文本发送到电子邮件正文?
谢谢
【问题讨论】:
-
您可以在发送邮件后尝试
$string .= file_get_contents($file);和/或输入您的$fclose($file);。似乎您可能过早关闭文件。检查文件权限。 -
$string .= file_get_contents($file);不起作用,它说我需要在那里有文件名。 $fclose($文件);在邮件功能之后也不起作用。
-
file_get_contents()不需要fopen(),因此也不需要fclose() -
你是说邮件没有被发送?或者当你收到邮件时它不包含
basic.txt的内容 -
邮件正在发送,我收到了主题标题,而不是输入为 $string 的正文