Jump to content

Email Pipe Script won't save attachments.


techiefreak05

Recommended Posts

Just as the title says.

 

In cPanel, I have it al configured just fine; the script recieves the email, and I do receieve an email back, but here's where I come into problems.

 

It simply will NOT save the attachments to the server, I've tried loads of different implementations I've found, and nothing's working.

 

pipe script:

#!/usr/local/bin/php
<?php
// Need PEAR installed
include('Mail.php');
include('Mail/mime.php');
require_once 'Mail/mimeDecode.php';

// read email using stdin
$fx = fopen("php://stdin", "r");
$email = "";
while (!feof($fx)) {
$email .= fread($fx,1024);
}

$params['include_bodies'] = true;
$params['decode_bodies'] = true;
$params['decode_headers'] = true;
$params['input'] = $email;
/*
$message=new Mail_mimeDecode();
$mailObj=$message->decode($params);
*/

$mailObj = Mail_mimeDecode::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 $pp){
  if ($pp->disposition=='attachment'){
    $tmp=$pp->d_parameters['filename'];
    if($tmp !== ""){
      $open = fopen($tmp, 'w');
      if($open){
        $write = fwrite($open,$pp->body);
        if(!$write){
          $err = "Cannot write to file: '".$tmp."' - var: ".$write;
        }
       }else{
        $err = "Cannot create/open file: '".$tmp."' - var: ".$open;
       }    
    }
  }  
}
$tox      = $from;
$subjectx = 'Your Photo was Uploaded!';
$messagex = $err;
$headersx = 'From: piculo.us Uploader <[email protected]>' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($tox, $subjectx, $messagex, $headersx);
exit;
?>

 

Here's the email I get back:

Cannot create/open file: '2879_1150712806251_1180540351_425140_7940412_n.jpg' - var:

 

as you can see, it is aware that an attachment exists, but it won't create the file, and fopen() doesn't say anything.

 

Any ideas??

Link to comment
https://forums.phpfreaks.com/topic/211256-email-pipe-script-wont-save-attachments/
Share on other sites

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.