> 백엔드 개발 > PHP 튜토리얼 > PHP处理postfix的邮件内容_PHP教程

PHP处理postfix的邮件内容_PHP教程

WBOY
풀어 주다: 2016-07-13 17:43:34
원래의
1114명이 탐색했습니다.

 

<ol class="dp-c">
<li class="alt"><span><span>01 <?php     </span></span></span></li>
<li><span> </span></li>
<li class="alt"><span>02      </span></li>
<li><span> </span></li>
<li class="alt"><span>03 #从输入读取到所有的邮件内容    </span></li>
<li><span> </span></li>
<li class="alt">
<span>04 </span><span class="vars">$email</span><span> = </span><span class="string">""</span><span>;    </span>
</li>
<li><span> </span></li>
<li class="alt">
<span>05 </span><span class="vars">$fd</span><span> = </span><span class="func">fopen</span><span>(</span><span class="string">"php://stdin"</span><span>, </span><span class="string">"r"</span><span>);    </span>
</li>
<li><span> </span></li>
<li class="alt">
<span>06 </span><span class="keyword">while</span><span> (!</span><span class="func">feof</span><span>(</span><span class="vars">$fd</span><span>)) {    </span>
</li>
<li><span> </span></li>
<li class="alt">
<span>07   </span><span class="vars">$email</span><span> .= </span><span class="func">fread</span><span>(</span><span class="vars">$fd</span><span>, 1024);    </span>
</li>
<li><span> </span></li>
<li class="alt"><span>08 }    </span></li>
<li><span> </span></li>
<li class="alt">
<span>09 fclose(</span><span class="vars">$fd</span><span>);    </span>
</li>
<li><span> </span></li>
<li class="alt"><span>10      </span></li>
<li><span> </span></li>
<li class="alt"><span>11 #记录所有的内容,测试    </span></li>
<li><span> </span></li>
<li class="alt">
<span>12 </span><span class="func">file_put_contents</span><span>(</span><span class="string">"/tmp/mail/"</span><span>.time(), </span><span class="vars">$email</span><span>);    </span>
</li>
<li><span> </span></li>
<li class="alt"><span>13      </span></li>
<li><span> </span></li>
<li class="alt"><span>14 #处理邮件    </span></li>
<li><span> </span></li>
<li class="alt">
<span>15 </span><span class="vars">$lines</span><span> = </span><span class="func">explode</span><span>(</span><span class="string">"
"</span><span>, </span><span class="vars">$email</span><span>);    </span>
</li>
<li><span> </span></li>
<li class="alt"><span>16      </span></li>
<li><span> </span></li>
<li class="alt">
<span>17 </span><span class="comment">// empty vars   </span><span> </span>
</li>
<li><span> </span></li>
<li class="alt">
<span>18 </span><span class="vars">$from</span><span> = </span><span class="string">""</span><span>;    </span>
</li>
<li><span> </span></li>
<li class="alt">
<span>19 </span><span class="vars">$date</span><span> = </span><span class="string">""</span><span>;    </span>
</li>
<li><span> </span></li>
<li class="alt">
<span>20 </span><span class="vars">$subject</span><span> = </span><span class="string">""</span><span>;    </span>
</li>
<li><span> </span></li>
<li class="alt">
<span>21 </span><span class="vars">$message</span><span> = </span><span class="string">""</span><span>;    </span>
</li>
<li><span> </span></li>
<li class="alt">
<span>22 </span><span class="vars">$splittingheaders</span><span> = true;    </span>
</li>
<li><span> </span></li>
<li class="alt"><span>23      </span></li>
<li><span> </span></li>
<li class="alt">
<span>24 </span><span class="keyword">for</span><span> (</span><span class="vars">$i</span><span>=0; </span><span class="vars">$i</span><span><span class="func">count</span><span>(</span><span class="vars">$lines</span><span>); </span><span class="vars">$i</span><span>++) {    </span></span>
</li>
<li><span> </span></li>
<li class="alt">
<span>25   </span><span class="keyword">if</span><span> (</span><span class="vars">$splittingheaders</span><span>) {    </span>
</li>
<li><span> </span></li>
<li class="alt"><span>26      </span></li>
<li><span> </span></li>
<li class="alt">
<span>27     </span><span class="comment">// look out for special headers   </span><span> </span>
</li>
<li><span> </span></li>
<li class="alt">
<span>28     </span><span class="keyword">if</span><span> (preg_match(</span><span class="string">"/^Subject: (.*)/"</span><span>, </span><span class="vars">$lines</span><span>[</span><span class="vars">$i</span><span>], </span><span class="vars">$matches</span><span>)) {    </span>
</li>
<li><span> </span></li>
<li class="alt">
<span>29       </span><span class="vars">$subject</span><span> = </span><span class="vars">$matches</span><span>[1];    </span>
</li>
<li><span> </span></li>
<li class="alt"><span>30     }    </span></li>
<li><span> </span></li>
<li class="alt">
<span>31     </span><span class="keyword">if</span><span> (preg_match(</span><span class="string">"/^From: (.*)/"</span><span>, </span><span class="vars">$lines</span><span>[</span><span class="vars">$i</span><span>], </span><span class="vars">$matches</span><span>)) {    </span>
</li>
<li><span> </span></li>
<li class="alt">
<span>32       </span><span class="keyword">if</span><span>(</span><span class="func">strpos</span><span>(</span><span class="vars">$lines</span><span>[</span><span class="vars">$i</span><span>],</span><span class="string">"<span>)){    </span></span>
</li>
<li><span> </span></li>
<li class="alt">
<span>33         </span><span class="comment">//the name exist too in from header   </span><span> </span>
</li>
<li><span> </span></li>
<li class="alt">
<span>34         </span><span class="vars">$data</span><span> = </span><span class="func">explode</span><span>(</span><span class="string"><span>,</span><span class="vars">$lines</span><span>[</span><span class="vars">$i</span><span>]);    </span></span>
</li>
<li><span> </span></li>
<li class="alt">
<span>35         </span><span class="vars">$from</span><span> = </span><span class="func">substr</span><span>(trim(</span><span class="vars">$data</span><span>[1]),0,-1);    </span>
</li>
<li><span> </span></li>
<li class="alt">
<span>36       }</span><span class="keyword">else</span><span>{    </span>
</li>
<li><span> </span></li>
<li class="alt">
<span>37         </span><span class="comment">//only the mail   </span><span> </span>
</li>
<li><span> </span></li>
<li class="alt">
<span>38         </span><span class="vars">$from</span><span> = </span><span class="vars">$matches</span><span>[1];    </span>
</li>
<li><span> </span></li>
<li class="alt"><span>39       }    </span></li>
<li><span> </span></li>
<li clas>
<p align="left"></p>
<div style="display:none;">
<span id="url" itemprop="url">http://www.bkjia.com/PHPjc/478830.html</span><span id="indexUrl" itemprop="indexUrl">www.bkjia.com</span><span id="isOriginal" itemprop="isOriginal">true</span><span id="isBasedOnUrl" itemprop="isBasedOnUrl">http://www.bkjia.com/PHPjc/478830.html</span><span id="genre" itemprop="genre">TechArticle</span><span id="description" itemprop="description">01?php 02 03#从输入读取到所有的邮件内容 04 $email = ; 05 $fd = fopen ( php://stdin , r ); 06 while (! feof ( $fd )){ 07 $email .= fread ( $fd ,1024); 08} 09fclose( $fd...</span>
</div>
<div class="art_confoot"></div>
</li>
</ol>
로그인 후 복사
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿