仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1066|回复: 19
打印 上一主题 下一主题

[学习教程] PHP网页设计PHP处置postfix的邮件内容

[复制链接]
飘灵儿 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-3 23:38:33 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
工具程序用来显示 Rasmus Lerdorf 的个人履历,以及统计网页流量。  
  1. 01 <?php     02       03 #从输出
    读取到一切
    的邮件内容     04 $email = "";     05 $fd = fopen("php://stdin", "r");     06 while (!feof($fd)) {     07   $email .= fread($fd, 1024);     08 }     09 fclose($fd);     10       11 #纪录
    一切
    的内容,测试     12 file_put_contents("/tmp/mail/".time(), $email);     13       14 #处置
    邮件     15 $lines = explode("\n", $email);     16       17 // empty vars     18 $from = "";     19 $date = "";     20 $subject = "";     21 $message = "";     22 $splittingheaders = true;     23       24 for ($i=0; $i<count($lines); $i++) {     25   if ($splittingheaders) {     26       27     // look out for special headers     28     if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {     29       $subject = $matches[1];     30     }     31     if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {     32       if(strpos($lines[$i],"<")){     33         //the name exist too in from header     34         $data = explode('<',$lines[$i]);     35         $from = substr(trim($data[1]),0,-1);     36       }else{     37         //only the mail     38         $from = $matches[1];     39       }     40     }     41     if (preg_match("/^Date: (.*)/", $lines[$i], $matches)) {     42       $date = $matches[1];     43     }     44   } else {     45     // not a header, but message     46     $message .= $lines[$i]."\n";     47   }     48       49   if (trim($lines[$i])=="") {     50     // empty line, header section has ended     51     $splittingheaders = false;     52   }     53 }     54       55 $when = date("Y-m-d G:i:s");     56 $data = explode('@',$from);     57 $username = $data[0];     58       59 #纪录
    到数据库     60 $sql = "insert into mails ( `username`, `from`, `subject`, `date`, `message`) values ( '$username', '$from', '$subject', '$when', '$message')";     61       62 #测试     63 file_put_contents("/tmp/mail2.log", $sql);     64 ?>   
复制代码
<P style="TEXT-INDENT: 2em">
刚开始因为习惯于ASP格式的写法,总是在这些方面出现问题,自己还总是找不到问题所在,这就提醒了自己,在写代码的时候一定要认真,不能粗心地老是少个“;”或者字母大小写不分,要不然很可能找半天都找不到错误。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-22 12:37

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表