Giter VIP home page Giter VIP logo

Comments (5)

zbateson avatar zbateson commented on August 24, 2024

Hi @channelriyas

Sure -- perhaps some extra documentation is needed there :) you should be able to:

$atts = $message->getAllAttachmentParts();
foreach ($atts as $ind => $part) {
    $filename = $part->getHeaderParameter(
        'Content-Type',
        'name',
        $part->getHeaderParameter(
             'Content-Disposition',
             'filename',
             '__unknown_file_name_' . $ind
        )
    );
    $out = fopen('/path/to/dir/' . $filename, 'w');
    stream_copy_to_stream($part->getContentResourceHandle(), $out);
}

I didn't run this, but that's the basic idea. Let me know if it works out or if some corrections are needed and I'll add it to the usage guide.

from mail-mime-parser.

channelriyas avatar channelriyas commented on August 24, 2024

Hi Zaahid,
Thanks for quick reply!

I just run this code but got error at this line
$atts = $message->getAllAttachmentParts();

PHP Fatal error: Call to a member function getAllAttachmentParts() on a non-object in /../../

is this familiar?

Thanks!

from mail-mime-parser.

zbateson avatar zbateson commented on August 24, 2024

Hi @channelriyas -

That probably means you haven't assigned anything to $message. If you look at the example on the project's front page you can see how $message is assigned:

// ...
$message = $mailParser->parse($handle);
// ...

unless something went wrong in the call to parse().

from mail-mime-parser.

channelriyas avatar channelriyas commented on August 24, 2024

Hi Zaahid,

Yes, figure out the issue, my mistake, accidentally $message replaced with body content, thats why error ;)

Anyway now attachments works well, I can move to specific dir as-well, here is my code some one will help.

#!/usr/bin/php -q
<?php
require_once 'vendor/autoload.php';
$mailParser = new ZBateson\MailMimeParser\MailMimeParser();

$handle = fopen ("php://stdin", 'r');
$message = $mailParser->parse($handle);         // returns a ZBateson\MailMimeParser\Message
fclose($handle);

$to  = $message->getHeaderValue('to'); 
$from  = $message->getHeaderValue('from');          // [email protected]
$from_name  = $message->getHeader('from')->getPersonName();    // Person Name
$subject  = $message->getHeaderValue('subject');       // The email's subject

$res = $message->getHtmlStream(); // getTextStream
$body_content = stream_get_contents($res);

$atts = $message->getAllAttachmentParts(); //get all attachments
if($atts){
    $ind = 0;
    foreach ($atts as $part) {
        $filename = $part->getHeaderParameter(
            'Content-Type',
            'name',
            $part->getHeaderParameter(
                 'Content-Disposition',
                 'filename',
                 '__unknown_file_name_' . $ind
            )
        );
        $out = fopen('/path/to/dir/' . $filename, 'w');
        stream_copy_to_stream($part->getContentResourceHandle(), $out);
    }
}
?>

Zaahid, Thank you very much, this is really awesome library!!!!!!!! 👍

Riyas.

from mail-mime-parser.

zbateson avatar zbateson commented on August 24, 2024

Excellent, happy to hear that Riyas :)

from mail-mime-parser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.