Jump to content

Read email attachments


The Little Guy

Recommended Posts

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

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);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.