The Little Guy Posted December 8, 2010 Share Posted December 8, 2010 I am piping email to a php script, from the email I want to get the email attachment that came with it. For our sake, the curent attachment I am working with is jpg. how can I get an image that is base64 encoded, then save it to a jpg file? "Content-Transfer-Encoding: base64" Link to comment https://forums.phpfreaks.com/topic/220982-read-email-attachments/ Share on other sites More sharing options...
The Little Guy Posted December 8, 2010 Author Share Posted December 8, 2010 Oh, and here is my current code: #!/usr/local/php5/bin/php <?php function replace_newline($string) { return (string)str_replace(array("\r", "\r\n", "\n"), array('', '', ''), $string); } $fd = fopen("php://stdin", "r"); $msg = ""; while (!feof($fd)){ $msg .= fread($fd, 8192); } preg_match("~Content-Type: multipart/mixed; boundary=(.+)~", $msg, $boundries); $bound = trim(replace_newline($boundries[1])); $opt = preg_split("~--$bound~", $msg); preg_match("~Content-Transfer-Encoding:(.+)~", $opt[2], $matches); $ttype = trim(replace_newline($matches[1])); $sections = preg_split("~\r\n~", $opt[2]); //if($ttype=='base64'){ $item = base64_decode($sections[2]); //} $handle = fopen('/home/envne/envne.com/images/file.txt', 'w'); fwrite($handle, $item); ?> Link to comment https://forums.phpfreaks.com/topic/220982-read-email-attachments/#findComment-1144251 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.