PHP头条
热点:

PHP处理postfix的邮件内容


 

  1. 01 <?php    
  2.  
  3. 02      
  4.  
  5. 03 #从输入读取到所有的邮件内容    
  6.  
  7. 04 $email = "";    
  8.  
  9. 05 $fd = fopen("php://stdin""r");    
  10.  
  11. 06 while (!feof($fd)) {    
  12.  
  13. 07   $email .= fread($fd, 1024);    
  14.  
  15. 08 }    
  16.  
  17. 09 fclose($fd);    
  18.  
  19. 10      
  20.  
  21. 11 #记录所有的内容,测试    
  22.  
  23. 12 file_put_contents("/tmp/mail/".time(), $email);    
  24.  
  25. 13      
  26.  
  27. 14 #处理邮件    
  28.  
  29. 15 $lines = explode(" "$email);    
  30.  
  31. 16      
  32.  
  33. 17 // empty vars    
  34.  
  35. 18 $from = "";    
  36.  
  37. 19 $date = "";    
  38.  
  39. 20 $subject = "";    
  40.  
  41. 21 $message = "";    
  42.  
  43. 22 $splittingheaders = true;    
  44.  
  45. 23      
  46.  
  47. 24 for ($i=0; $i<count($lines); $i++) {    
  48.  
  49. 25   if ($splittingheaders) {    
  50.  
  51. 26      
  52.  
  53. 27     // look out for special headers    
  54.  
  55. 28     if (preg_match("/^Subject: (.*)/"$lines[$i], $matches)) {    
  56.  
  57. 29       $subject = $matches[1];    
  58.  
  59. 30     }    
  60.  
  61. 31     if (preg_match("/^From: (.*)/"$lines[$i], $matches)) {    
  62.  
  63. 32       if(strpos($lines[$i],"<")){    
  64.  
  65. 33         //the name exist too in from header    
  66.  
  67. 34         $data = explode(<,$lines[$i]);    
  68.  
  69. 35         $from = substr(trim($data[1]),0,-1);    
  70.  
  71. 36       }else{    
  72.  
  73. 37         //only the mail    
  74.  
  75. 38         $from = $matches[1];    
  76.  
  77. 39       }    
  78.  
  79. www.phpzy.comtrue/phprm/22917.htmlTechArticlePHP处理postfix的邮件内容 01?php 02 03#从输入读取到所有的邮件内容 04 $email = ; 05 $fd = fopen ( php://stdin , r ); 06 while (! feof ( $fd )){ 07 $email .= fread ( $fd ,1024); 08} 09fclose( $fd ); 10 11#记录所有的内容...

相关文章

    暂无相关文章

PHP之友评论

今天推荐