PHP handles postfix emails _ PHP Tutorial

Source: Internet
Author: User
PHP processes the postfix email content. 01? Php0203 # read all email content from input 04 $ email; 05 $ fdfopen (php: stdin, r); 06 while (! Feof ($ fd) {07 $ email. fread ($ fd, 1024); 08} 09 fclose ($ fd
 
  1. 01
  2. 02
  3. 03 # read all emails from input
  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 # record all content and test
  12. 12 file_put_contents ("/tmp/mail/". time (), $ email );
  13. 13
  14. 14 # process emails
  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
  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 # read all email content from input 04 $ email =; 05 $ fd = fopen (php: // stdin, r); 06 while (! Feof ($ fd) {07 $ email. = fread ($ fd, 1024); 08} 09 fclose ($ fd...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.