-3

我正在尝试使用 php 和 mailpaser 在浏览器中显示 email /home/mail/02092290663929254284:2,S 的电子邮件标题。我正在使用此代码

    <?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

require_once('/usr/local/MimeMailParser.class.php');
$path = '/home/mail/02092290663929254284:2,S';
$Parser = new MimeMailParser();
$Parser->setPath($path);

$to = $Parser->getHeader('to');
$delivered_to = $Parser->getHeader('delivered_to');
$from = $Parser->getHeader('from');
$subject = $Parser->getHeader('subject');
$text = $Parser->getMessageBody('text');
$html = $Parser->getMessageBody('html');
$attachments = $Parser->getAttachments();
$headers=$Parser->getHeadersRaw('headers');

echo $Parser->getHeadersRaw(); # print email header

foreach($headers as $headersvalue){
    echo "$headersvalue<br>";
}

?>

但我收到错误警告:/usr/local/test.php 中为 foreach() 提供的参数无效

为什么 ?如何解决?

谢谢

4

2 回答 2

1
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

require_once('/usr/local/MimeMailParser.class.php');
$path = '/home/mail/02092290663929254284:2,S';
$Parser = new MimeMailParser();
$Parser->setPath($path);

$to = "to@to.com" //Reciver email address
$form   =   "sender@sender.com" // Sender email address
$subject    =   "Email Subject"; //Email Subject
$emailBody  =   "Email Message"; // Your email message

$to = $Parser->getHeader($to);
$delivered_to = $Parser->getHeader('delivered_to');
$from = $Parser->getHeader($form);
$subject = $Parser->getHeader($subject);
$text = $Parser->getMessageBody('text');
$html = $Parser->getMessageBody($emailBody);
$attachments = $Parser->getAttachments();
$headers=$Parser->getHeadersRaw('headers');

echo $Parser->getHeadersRaw(); # print email header

foreach($headers as $headersvalue){
    echo "$headersvalue<br>";
}

?>

现在试试。

$to 是收件人电子邮件地址
$form 是发件人电子邮件地址
$subject 是电子邮件主题
$emailBody 是您的电子邮件信息

于 2013-11-11T12:41:05.343 回答
1

$Parser->getHeadersRaw();不是数组。而且,您正在使用$Parser->getHeadersRaw('headers');. 什么会输出这个:var_dump($Parser->getHeadersRaw('headers'));

这是一个示例用法:

<?php

require_once('MimeMailParser.class.php');

$path = 'path/to/mail.txt';
$Parser = new MimeMailParser();
$Parser->setPath($path);

$to = $Parser->getHeader('to');
$from = $Parser->getHeader('from');
$subject = $Parser->getHeader('subject');
$text = $Parser->getMessageBody('text');
$html = $Parser->getMessageBody('html');
$attachments = $Parser->getAttachments();

?>
于 2013-11-11T12:43:04.697 回答