Note that there are some explanatory texts on larger screens.

plurals
  1. POparsing email attachments in php
    text
    copied!<p>I have a .forward.postix that is piping incoming emails to a shell account, and consequently to a PHP script that parses the emails - awesome.</p> <p>As of now, and based on everything I've seen online, I'm using the <code>explode('From: ', $email);</code> approach to split everything down into the vars I need for my database.</p> <p>Enter attachments! Using the same approach, I'm doing this to pull out a jpg attachment - but it appears not every email client formats the raw source the same way and it's causing some headaches!</p> <pre><code>$contentType1 = explode('Content-type: image/jpg;', $email); //start ContentType $contentType2 = explode("--Boundary_", $contentType1[1]); //end ContentType $jpg1 = explode("\n\n", $contentType2[0]); //double return starts base64 blob $jpg2 = explode("\n\n", $jpg1[1]); //double return marks end of base64 blob $image = base64_decode($jpg2[0]); //decode base64 blob into jpg raw </code></pre> <p><strong>Here's my issue:</strong> Not all mail clients - like GMail for example - list an attachment as <code>'Content-type: image/jpg'</code>. GMail puts in <code>'Content-Type: IMAGE/JPEG'</code> and sometimes sends it as <code>'Content-Type: image/jpeg'</code>! Which don't match my explode...</p> <p><strong>My Question:</strong> Does someone know a better way of finding the bounds of a base64 blob? or maybe a case-insensitive way of exploding the <code>'Content-Type:'</code> so I can then try against <code>image/jpg</code> or <code>image-jpeg</code> to see what matches?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload