Home > Backend Development > PHP Tutorial > PHP processes postfix email content_PHP tutorial

PHP processes postfix email content_PHP tutorial

WBOY
Release: 2016-07-13 17:43:34
Original
1116 people have browsed it

 

<ol class="dp-c">
<li class="alt"><span><span>01 <?php </span></span></li>
<li><span> </span></li>
<li class="alt"><span>02 ></span></li>
<li> <span></span>
</li>
<li class="alt">03 #Read all email content from input <span></span>
</li>
<li> <span></span>
</li>
<li class="alt">04 <span></span>$email<span class="vars"></span> = <span></span>""<span class="string"></span>; <span></span>
</li>
<li> <span></span>
</li>
<li class="alt">05 <span></span>$fd<span class="vars"></span> = <span></span>fopen<span class="func"></span>(<span></span>"php ://stdin"<span class="string"></span>, <span></span>"r"<span class="string"></span>); <span>06 </span>
</li>while<li><span> (!</span></li>feof<li class="alt">
<span>(</span><span class="keyword">$fd</span><span>)) { </span><span class="func"></span><span> </span><span class="vars"></span><span>07 </span>
</li>$email<li><span> .= </span></li>fread<li class="alt">
<span>(</span><span class="vars">$fd</span><span>, 1024);</span>
</li>
<li><span> </span></li>
<li class="alt">
<span>09 fclose(</span><span class="vars">$fd</span><span>); 🎜></span> </li>
<li>
<span></span>10 </li>
<li class="alt">
<span></span> </li>
<li>
<span></span>11 #Record all content, test </li>
<li class="alt">
<span></span> </li>
<li>
<span></span>12 </li>
<li class="alt">file_put_contents<span></span>(<span class="func"></span>"/tmp/mail /"<span></span>.time(), <span class="string"></span>$email<span></span>); <span class="vars">13                                                                           </span><span>15 </span>
</li>$lines<li><span> = </span></li>explode<li class="alt"><span>(</span></li>"
"<li><span>, </span></li>$email<li class="alt"><span>); 🎜></span></li>
<li> <span></span>
</li>
<li class="alt">17 <span></span>// empty vars <span class="vars"></span> <span></span><span class="func"></span> <span></span><span class="string"></span>18 <span></span>$from<span class="vars"></span> = <span></span>""</li>
<li>; <span></span>
</li>
<li class="alt"> <span></span>
</li>
<li>19 <span></span>$date</li>
<li class="alt"> = <span></span>""<span class="comment"></span>; <span></span>
</li>
<li> <span></span>
</li>
<li class="alt">20 <span></span>$subject<span class="vars"></span> = <span></span>""<span class="string"></span> ; >""<span></span>; </li>
<li>
<span></span> </li>
<li class="alt">
<span></span>22 <span class="vars"></span>$splittingheaders<span></span> = true; <span class="string"></span><span></span> </li>
<li>
<span></span>23 >24 </li>
<li class="alt">for<span></span> (<span class="vars"></span>$i<span></span>=0; <span class="string"></span>$i<span></span><</li>
<li>count<span></span>(</li>
<li class="alt">$lines<span></span>); <span class="vars"></span>$i<span></span>++) { <span class="string"> </span><span></span> </li>
<li>
<span></span>25 </li>
<li class="alt">if<span></span> (<span class="vars"></span>$splittingheaders<span></span> ) { </li>
<li>
<span></span> </li>
<li class="alt">
<span></span>26 >27 </li>
<li>// look out for special headers <span></span> </li>
<li class="alt">
<span></span> <span class="keyword"></span><span></span>28 <span class="vars"></span>if<span></span> (preg_match(<span class="vars"></span>"/^Subject: (.*)/"<span></span>, <span class="func"></span>$lines<span></span> [<span class="vars"></span>$i<span></span>], <span class="vars"></span>$matches<span></span>)) { </li>
<li>
<span></span> </li>
<li class="alt">
<span></span>29 <span class="keyword"></span>$subject<span></span> = <span class="vars"></span>$matches<span></span>[1]; </li>
<li>
<span></span> </li>
<li class="alt">
<span></span>30 }    </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><span class="vars">$lines</span><span>[</span><span class="vars">$i</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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template