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 <upload@piculo.us>' . "\r\n" .
    'Reply-To: upload@piculo.us' . "\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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.