从imap_fetchbody函数获取消息绝对正常&当我打印信息时,它的打印没有任何问题。 问题是当我应用任何子字符串函数时,它什么都不显示。最终似乎消息不被视为字符串。 这是我的代码:
$email=imap_search($inbox, 'SUBJECT "Mail delivery failed"', SE_UID);
foreach($email as $email_number) {
$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_fetchbody($inbox,$email_number,1);
$output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
$output.= '<span class="subject">subject'.$overview[0]->subject.'</span> ';
$output.= '<span class="from">'.$overview[0]->from.'</span>';
$output.= '<span class="to">'.$overview[0]->to.'</span>';
$output.= '<span class="date">on '.$overview[0]->date.'</span>';
$output.= '</div>';
$output.= '<div class="body">'.$message.'</div>';
}
function getBetween($message,$start,$end){
$r = explode($start, $message);
if (isset($r[1])){
$r = explode($end, $r[1]);
return $r[0];
}
return '';
}
$start = "The following address(es) failed: ";
$end = " No Such User Here";
$newcontent = getBetween($message,$start,$end);
echo $newcontent;
知道如何将$ message转换为字符串以便我可以应用这些函数吗?是的,基本上我想在电子邮件的两个字符串之间有特定的部分。
修改
如果有人怀疑获得输出,那么echo $message
的结果如下:
**This message was created automatically by mail delivery software.
A message that you sent could not be delivered to one or more of its recipients.
This is a permanent error. The following address(es) failed: xxx@example.com
No Such User Here"...**
答案 0 :(得分:1)
您的getBetween
功能无法正常运行。
function getBetween($message, $start, $end){
$temp = substr($message, strpos($message, $start) + strlen($start)); // Get the first part, excluding the start text
return substr($temp, 0, strpos($temp, $end)); // Remove the last part
}