国产探花免费观看_亚洲丰满少妇自慰呻吟_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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 台前县| 新昌县| 康保县| 共和县| 高密市| 鸡西市| 柳江县| 四子王旗| 湄潭县| 牙克石市| 修武县| 亳州市| 马关县| 祁阳县| 岱山县| 交城县| 阳泉市| 格尔木市| 进贤县| 科尔| 濮阳县| 澄江县| 烟台市| 兴海县| 无极县| 淮北市| 建湖县| 卢湾区| 潮安县| 阿坝县| 长顺县| 墨竹工卡县| 内丘县| 海丰县| 龙口市| 新兴县| 石屏县| 定安县| 章丘市| 沂南县| 高唐县|