douwei6478 2014-08-28 11:31 采纳率: 100%
浏览 109
已采纳

发送邮件的Cron作业发送空白电子邮件[关闭]

I'm using this simple script to detect website content change and mail if there is a change.I've set a cron job to run the script everyday and it's working fine but when script detects a change it sends blank email without body.Why thi is happening?Am I doing something wrong here(in the mail part)?

<?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
";
 $headers.= "Content-type: text/html; charset=iso-8859-1
";
 $headers.= "From: $from
";

 $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条回答 默认 最新

  • dsideal2015 2014-08-28 11:33
    关注

    You're overwriting the previously-assigned content with:

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

    Change it to:

    $message .= '</body></html>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64