设置发送邮件的Cron作业正在发送空白电子邮件

时间:2014-08-28 11:31:09

标签: php email cron

我正在使用这个简单的脚本检测网站内容更改和邮件,如果有更改。我已经设置了一个cron作业,每天运行脚本,它运行正常但是当脚本检测到更改时,它会发送空白电子邮件而不会身体。为什么会这样?我在这里做错了什么(在邮件部分)?

<?php

$contents = file_get_contents('http://izoneknr.com');
$hash     = file_get_contents('../heimdall/heimdall.txt'); 

if ($hash == ($pageHash = md5($contents))) 
{
 echo " the content is the same";
} 
else 
{

 $from = "Heimdall";
 $EmailTo = "smckannur@gmail.com,sourab.cc@gmail.com"; // Your email address here
 $Subject = "WEBSITE MODIFICATION ALERT";

 $headers.= "MIME-version: 1.0\n";
 $headers.= "Content-type: text/html; charset=iso-8859-1\n";
 $headers.= "From: $from\n";

 $message = '<html><body>';
 $message.= '<p>This is an automated response from mysite.The bridge is open.</p><br>';
 $message.= '<p>m7mysite has been updated.</p>';
 $message = '</body></html>';

 $success = mail($EmailTo, $Subject, $message,$headers);

 // store the new hash in the file
 $fp = fopen('../heimdall/heimdall.txt', 'w');
 fwrite($fp, $pageHash);
 fclose($fp);

}

1 个答案:

答案 0 :(得分:2)

您使用以下方法覆盖以前分配的内容:

$message = '</body></html>';

将其更改为:

$message .= '</body></html>';