开发者

Parse email sent from Outlook piped to php

开发者 https://www.devze.com 2023-02-28 18:02 出处:网络
Using this tut: parse emails I was able to get email piping, and attachment/body parsing totally working....as long as the email is not sent from outlook.

Using this tut: parse emails

I was able to get email piping, and attachment/body parsing totally working....as long as the email is not sent from outlook.

It executes perfectly from gmail, and thunderbird, however when the incoming email is sent from outlook the script fails. I figure it has something to do with how outlook formats its messages (in the comments on the tutorial site some开发者_如何转开发one mentions outlook not being compliant), but truthfully the issue is above my head. Any help would be appreciated, thanks.

fyi: this is the newest version of outlook (win7).


As you have encountered, Outlook is the scourge of the email universe. You'll notice that the source provided in the tutorial you're using refers several times to content encoded as text/plain. The email being sent from Outlook likely contains text/html content instead of or in addition to the plaintext.

Depending on what you wish to do with the content of the email, you may be able to adapt the script to accept text/html encoded content as well by inserting a duplicate body search below the existing one like so:

//get the message body  
if(substr($decoded[0]['Headers']['content-type:'],0,strlen('text/html')) == 'text/html' && isset($decoded[0]['Body'])){  

    $body = $decoded[0]['Body'];  

} elseif(substr($decoded[0]['Parts'][0]['Headers']['content-type:'],0,strlen('text/html')) == 'text/html' && isset($decoded[0]['Parts'][0]['Body'])) {  

    $body = $decoded[0]['Parts'][0]['Body'];  

} elseif(substr($decoded[0]['Parts'][0]['Parts'][0]['Headers']['content-type:'],0,strlen('text/html')) == 'text/html' && isset($decoded[0]['Parts'][0]['Parts'][0]['Body'])) {  

    $body = $decoded[0]['Parts'][0]['Parts'][0]['Body'];  

}  

Which certainly isn't pretty, but should retrieve the HTML content coming from Outlook if it is detected.

If you need to actually parse the HTML content, your problem will be a bit more complicated. Your next step would be to take a look at some of the answers for this question: Robust, Mature HTML Parser for PHP.

Good luck!


Ok...

So I fixed it. I was setting up the pipe in Cpanel, because it's easier. I put the pipe under "account level filtering", worked great for anything but outlook. I would have loved to have the script print data for debug, but it was never even executing when the email came from outlook. Looked in mail logs...nothing obvious. My admin on a whim suggested that I move the pipe to the "forwarders" section in cpanel. Well now it works perfect. Must be a bug in cpanel. Why is it the more you learn about computers the less sense they make.

Just a couple other tweaks I had to implement:

A) when writing/editing the script in a windows environment, hidden characters are added. To fix this, I upload the php file, and open it in the cpanel filemanager (us-ascii), and save it. This removes the characters. (could obviously open in *nix also) B) I had to chmod to 755, or it would not run. Scripts sitting outside my \www so no worries. C) My shebang had to be: #!/usr/bin/php -q. The q was necessary to get it running.

Hope this helps someone else.

0

精彩评论

暂无评论...
验证码 换一张
取 消