【问题标题】:Cron job set to send mail is sending blank emails [closed]设置为发送邮件的 Cron 作业正在发送空白电子邮件 [关闭]
【发布时间】:2014-08-28 19:34:13
【问题描述】:

我正在使用这个简单的脚本来检测网站内容更改并在有更改时发送邮件。我已经设置了一个 cron 作业来每天运行脚本并且它工作正常但是当脚本检测到更改时它会发送空白电子邮件而没有body.为什么会发生这种情况?我在这里做错了吗(在邮件部分)?

<?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);

}

【问题讨论】:

    标签: php email cron


    【解决方案1】:

    您正在使用以下内容覆盖先前分配的内容:

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

    改成:

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

    【讨论】:

      猜你喜欢
      • 2011-04-26
      • 1970-01-01
      • 2019-01-12
      • 1970-01-01
      • 2012-11-15
      • 1970-01-01
      • 1970-01-01
      • 2014-06-27
      • 1970-01-01
      相关资源
      最近更新 更多