国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

PHP處理postfix郵件內容的方法

2024-05-04 23:36:17
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了PHP處理postfix郵件內容的方法,涉及php讀取、正則匹配郵件內容的相關技巧,需要的朋友可以參考下

本文實例講述了PHP處理postfix郵件內容的方法。分享給大家供大家參考。具體如下:

 

 
  1. <?php 
  2. //從輸入讀取到所有的郵件內容 
  3. $email = ""
  4. $fd = fopen("php://stdin""r"); 
  5. while (!feof($fd)) { 
  6. $email .= fread($fd, 1024); 
  7. fclose($fd); 
  8. //記錄所有的內容,測試 
  9. file_put_contents("/tmp/mail/".time(), $email); 
  10. //處理郵件 
  11. $lines = explode("/n"$email); 
  12. // empty vars 
  13. $from = ""
  14. $date = ""
  15. $subject = ""
  16. $message = ""
  17. $splittingheaders = true; 
  18. for ($i=0; $i<count($lines); $i++) { 
  19. if ($splittingheaders) { 
  20. // look out for special headers 
  21. if (preg_match("/^Subject: (.*)/"$lines[$i], $matches)) { 
  22. $subject = $matches[1]; 
  23. if (preg_match("/^From: (.*)/"$lines[$i], $matches)) { 
  24. if(strpos($lines[$i],"<")){ 
  25. //the name exist too in from header 
  26. $data = explode('<',$lines[$i]); 
  27. $from = substr(trim($data[1]),0,-1); 
  28. }else
  29. //only the mail 
  30. $from = $matches[1]; 
  31. if (preg_match("/^Date: (.*)/"$lines[$i], $matches)) { 
  32. $date = $matches[1]; 
  33. else { 
  34. // not a header, but message 
  35. $message .= $lines[$i]."/n"
  36. if (trim($lines[$i])=="") { 
  37. // empty line, header section has ended 
  38. $splittingheaders = false; 
  39. $when = date("Y-m-d G:i:s"); 
  40. $data = explode('@',$from); 
  41. $username = $data[0]; 
  42. //記錄到數據庫 
  43. $sql = "insert into mails ( `username`, `from`, `subject`, `date`, `message`) values ( '$username', '$from', '$subject', '$when', '$message')"
  44. //測試 
  45. file_put_contents("/tmp/mail2.log"$sql); 
  46. ?> 

希望本文所述對大家的php程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 秦皇岛市| 项城市| 滨州市| 诸城市| 蒙山县| 新宾| 温宿县| 大丰市| 塔城市| 富裕县| 保靖县| 东源县| 莆田市| 哈尔滨市| 冷水江市| 锡林浩特市| 乐都县| 苍梧县| 康平县| 麟游县| 宁都县| 安康市| 西峡县| 赤城县| 扶绥县| 西充县| 禄丰县| 观塘区| 友谊县| 郎溪县| 正阳县| 曲水县| 萨迦县| 梧州市| 乌拉特中旗| 来安县| 铁岭县| 昌乐县| 安图县| 望江县| 台州市|