PHP處理postfix的郵件內容_PHP教程

來源:互聯網
上載者:User
 
  1. 01
  2. 02
  3. 03 #從輸入讀取到所有的郵件內容
  4. 04 $email = "";
  5. 05 $fd = fopen("php://stdin", "r");
  6. 06 while (!feof($fd)) {
  7. 07 $email .= fread($fd, 1024);
  8. 08 }
  9. 09 fclose($fd);
  10. 10
  11. 11 #記錄所有的內容,測試
  12. 12 file_put_contents("/tmp/mail/".time(), $email);
  13. 13
  14. 14 #處理郵件
  15. 15 $lines = explode("", $email);
  16. 16
  17. 17 // empty vars
  18. 18 $from = "";
  19. 19 $date = "";
  20. 20 $subject = "";
  21. 21 $message = "";
  22. 22 $splittingheaders = true;
  23. 23
  24. 24 for ($i=0; $i<count($lines); $i++) {
  25. 25 if ($splittingheaders) {
  26. 26
  27. 27 // look out for special headers
  28. 28 if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
  29. 29 $subject = $matches[1];
  30. 30 }
  31. 31 if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
  32. 32 if(strpos($lines[$i],"<")){
  33. 33 //the name exist too in from header
  34. 34 $data = explode(<,$lines[$i]);
  35. 35 $from = substr(trim($data[1]),0,-1);
  36. 36 }else{
  37. 37 //only the mail
  38. 38 $from = $matches[1];
  39. 39 }
  40. http://www.bkjia.com/PHPjc/478830.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478830.htmlTechArticle01?php 02 03#從輸入讀取到所有的郵件內容 04 $email = ; 05 $fd = fopen ( php://stdin , r ); 06 while (! feof ( $fd )){ 07 $email .= fread ( $fd ,1024); 08} 09fclose( $fd...

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.