afrojojo Posted February 15, 2010 Share Posted February 15, 2010 I found this earlier and can't get it too work. What am I doing wrong? http://zarski.com/index.php?/archives/25-Automatically-processing-an-email-with-attachments-using-PHP-and-PEAR-Mail-class.html Link to comment https://forums.phpfreaks.com/topic/192101-processing-an-email-with-attachments-using-php-and-pear-mail-class/ Share on other sites More sharing options...
trq Posted February 15, 2010 Share Posted February 15, 2010 What am I doing wrong? We wouldn't know. It helps us help you if you actually describe your problem. Link to comment https://forums.phpfreaks.com/topic/192101-processing-an-email-with-attachments-using-php-and-pear-mail-class/#findComment-1012451 Share on other sites More sharing options...
afrojojo Posted February 15, 2010 Author Share Posted February 15, 2010 #!/usr/local/bin/php <?php // Need PEAR installed include('Mail.php'); include('Mail/mime.php'); require_once 'Mail/mimeDecode.php'; // read email using stdin $fd = fopen("php://stdin", "r"); $email = ""; while (!feof($fd)) { $email .= fread($fd, 1024); } fclose($fd); $params['include_bodies'] = true; $params['decode_bodies'] = true; $params['decode_headers'] = true; $message=new Mail_mimeDecode($email); $mailObj=$message->decode($params); // Who is it from $from=$mailObj->headers['from']; // Get Subject $subj=$mailObj->headers['subject']; // Get Message Body $body=$mailObj->parts[0]->body; $gather="From:$from\nSubject:$subj\nBody:$body"; // Get and Save the Attachments foreach($mailObj->parts as $key=>$val): $tmpObj=$mailObj->parts[$key]; $tmp=$tmpObj->d_parameters['filename']; if(!empty($tmp)): $fd = fopen($tmp, 'w'); fwrite($fd, $tmpObj->body); endif; endforeach; ?> When I send an email with no attachment from a local mail client and echo the $body variable, it shows up empty. The body shows up when there is an attachment though. It also shows up when sent from a webmail app whether there is an attachment or not. What gives? Link to comment https://forums.phpfreaks.com/topic/192101-processing-an-email-with-attachments-using-php-and-pear-mail-class/#findComment-1012757 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.