Hi,
I'm getting emails from an address trough a script and I want to copy the
attached files on the server. I can get the files and copy them on the
server (trough the function below) BUT the files are not valid (images
cannot be displayed)
how can I solve this?
------------------------------------------
function get_attachments ($mbox,$msgno){
$o = imap_fetchstruc ture($mbox, $msgno);
$dir = "C:/AppServ/www/getinfo/fileadmin/testmail/"; // TEST
if ($o->type == 1 || ($o->ifsubtype == 1 && $o->subtype == 'MIXED')) {
$parts = $o->parts;
$i=1;
$retour = array();
foreach($parts as $part) {
$fname = '';
if (!isset($part->encoding) && $part->encoding == 3) {
$str = imap_base64(tri m(@imap_fetchbo dy($mbox, $msgno,$i)));
} else {
$str = imap_fetchbody( $mbox, $msgno,$i);
}
if ($part->ifdparameter s == 1) {
$dparams = $part->dparameters;
foreach($dparam s as $dparam) {
if ($dparam->attribute == "FILENAME") {
$fname = $dparam->value;
}
}
}
if ($fname=="") {
if ($part->ifparameters == 1) {
$params = $part->parameters;
foreach($params as $param) {
if ($param->attribute == "NAME") {
$fname = $param->value;
}
}
}
}
if ($fname=="") {$fname = "part$i";}
$fp = fopen($dir.$fna me,"wb");
if (!$fp) { return FALSE; }
fwrite($fp,$str );
fclose($fp);
$i++;
}
return $retour;
} else {
return "no attach";
}
}
I'm getting emails from an address trough a script and I want to copy the
attached files on the server. I can get the files and copy them on the
server (trough the function below) BUT the files are not valid (images
cannot be displayed)
how can I solve this?
------------------------------------------
function get_attachments ($mbox,$msgno){
$o = imap_fetchstruc ture($mbox, $msgno);
$dir = "C:/AppServ/www/getinfo/fileadmin/testmail/"; // TEST
if ($o->type == 1 || ($o->ifsubtype == 1 && $o->subtype == 'MIXED')) {
$parts = $o->parts;
$i=1;
$retour = array();
foreach($parts as $part) {
$fname = '';
if (!isset($part->encoding) && $part->encoding == 3) {
$str = imap_base64(tri m(@imap_fetchbo dy($mbox, $msgno,$i)));
} else {
$str = imap_fetchbody( $mbox, $msgno,$i);
}
if ($part->ifdparameter s == 1) {
$dparams = $part->dparameters;
foreach($dparam s as $dparam) {
if ($dparam->attribute == "FILENAME") {
$fname = $dparam->value;
}
}
}
if ($fname=="") {
if ($part->ifparameters == 1) {
$params = $part->parameters;
foreach($params as $param) {
if ($param->attribute == "NAME") {
$fname = $param->value;
}
}
}
}
if ($fname=="") {$fname = "part$i";}
$fp = fopen($dir.$fna me,"wb");
if (!$fp) { return FALSE; }
fwrite($fp,$str );
fclose($fp);
$i++;
}
return $retour;
} else {
return "no attach";
}
}
Comment