开发者

Zend_Mail sending special characters breaking email in client

I am using Zend_Mail to send an email of a log file, but it is sending dodgy characters that the mail clients don't like.

My code:

<?php
$sBody = "errors.log (>= WARN):\n\n";
$rFile = fopen($sErrorsLog, "r");
while (!feof($rFile))
{
    $sLine = fgets($rFile);
    $sBody.= $sLine;
}

$oMail = new Zend_Mail();
$oMail->addTo($sTo)
      ->setFrom($sFrom)
      ->setSubject($sSubject)
      ->setBodyText($sMessage);

The email body I receive:

errors.log (>= WARN):

timestamp|2010-07-05T09:48:03+10:00 message|O:11:"ArrayObject":3:{s:9:"exception";O:32:"Zend_Controller_Action_Exception":7:{s:25:"

The error log contains (this is an extract from the top)

timestamp|2010-07-05T09:48:03+10:00 message|O:11:"ArrayObject":3:{s:9:"exception";O:32:"Zend_Controller_Action_Exception":7:{s:25:"Zend_Exception_previous";N;s:10:"*message";s:64:"Action "crgdtgdf" does not exist and was not trapped in __call()";s:17:"Exceptionstring";s:0:"";s:7:"*code";i:404;s:7:"*file";s:73:"/var/www/development/workspaces/s.rees/library/Zend/Controller/Action.php";s:7:"*line";i:485;s:16:"Exceptiontrace";a:4:{i:0;a:6:{s:4:"file";s:73:"/var/www/development/workspaces/s.rees/library/Zend/Controller/Action.php";s:4:"line";i:515;s:8:"function";s:6:"__call";s:5:"class";s:22:"Zend_Controller_Action";s:4:"type";s:2:"->";s:4:"args";a:2:{i:0;s:14:"crgdtgdfAction";i:1;a:0:{}}}i:1开发者_运维知识库;a:6:

Any ideas how I can filter/encode the email so all of the log output is shown? I really need it emailed out with all the details.


PHP's serialized data includes a null byte before the private or protected members of any serialized object.

You are going to need to either unserialize and reprocess the output, or you're going to need to strip the null bytes before sending them out in an email.


I solved this using:

$text = filter_var($text, FILTER_SANITIZE_SPECIAL_CHARS);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜