2012-04-03 2 views
0

Hier ist eine Beispiel-E-Mail. Was ich möchte verwendet zend Mail tun, um die E-Mail mit dem speziellen Header, um herauszufiltern und Thema, hier sind meine reg experssionWie verwende ich Zend-Mail, um die Mail-Nachricht zu manipulieren?

$pattern_subject = "#delivery errors|delivery failure|delivery has failed|delivery notification|delivery problem|delivery status notif|failure delivery|failure notice|mail delivery failed|mail delivery system|mail status report|mail system error|mail transaction failed|mailserver notification|mdaemon notification|nondeliverable mail|returned email|returned mail|returned mail|returned to sender|returning message to sender|spam eater|undeliverable|undelivered mail|warning: message#i"; 

$pattern_body = "#554 delivery error|554 TRANSACTION FAILED|Action: failed|Delivery attempts will continue to be made for|delivery temporarily suspended|Invalid recipient|is not a valid mailbox|Mail rejected by Windows Live Hotmail for policy reasons|mailbox is full|Mailbox quota usage exceeded|mailbox unavailable|my badmailfrom list|no mailbox here by that name|no such address|No such user here|not yet been delivered|Over quota|PERM_FAILURE: DNS Error: Domain name not found|Recipient address rejected|retry timeout exceeded|Status: 4.4.1|The account or domain may not exist, they may be blacklisted, or missing the proper dns entries.|The following address doesn't exist|The message that you sent was undeliverable to the following|The recipient name is not recognized|This Gmail user does not exist|This is a permanent error|Unrouteable address|unrouteable mail domain|User mailbox exceeds allowed size|User unknown in virtual alias table|User unknown#i"; 

One für das Thema und eine für Körper, wie kann ich

1) Verwenden Sie sie, um die E-Mail zu filtern und nur zu bekommen, was der reg exp entspricht?

2) Holen Sie sich das Mail mit anderen Teil, was ich brauche, ist separat von

erhalten Datum, Header, Body

Hier ist mein versucht, Code (die imap-Setup) ignoriert, aber es druckt nur den Header aus und nicht gefiltert.

foreach ($mail as $message) { 
foreach ($message->getHeaders() as $name => $value) { 
    if (is_string($pattern_subject)) { 
     echo "$name: $value\n"; 
     echo "<br>"; 
     } 

} 

} 

Danke

Antwort

3

Dieses Beispiel zeigt Ihnen, wie E-Mail-Teile zu bekommen, und herauszufiltern Nachrichten nach Thema, tun gleiche gilt für $body.

/* @var $message Zend_Mail_Message */ 
    foreach ($mail as $i => $message) { 
     if (!preg_match($pattern_subject, $message->subject)) { 
      continue; 
     } 

     echo $message->date . "\n"; 
     echo $message->subject . "\n"; 
     $body = null; 
     foreach (new RecursiveIteratorIterator($message) as $part) { 
      if (strtok($part->contentType, ';') == 'text/plain') { 
       $body = $part; 
       break; 
      } 
     } 
     echo $body."\n"; 
    } 
Verwandte Themen