Advertisement
Guest User

Untitled

a guest
Jun 10th, 2018
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. <?php
  2. // Include the library first
  3. require_once __DIR__.'/vendor/autoload.php';
  4.  
  5. $path = 'path/to/mail.txt';
  6. $Parser = new PhpMimeMailParser\Parser();
  7.  
  8. // There are four methods available to indicate which mime mail to parse.
  9. // You only need to use one of the following four:
  10.  
  11. // 1. Specify a file path to the mime mail.
  12. $Parser->setPath($path);
  13.  
  14. // 2. Specify a php file resource (stream) to the mime mail.
  15. $Parser->setStream(fopen($path, "r"));
  16.  
  17. // 3. Specify the raw mime mail text.
  18. $Parser->setText(file_get_contents($path));
  19.  
  20. // 4. Specify a stream to work with mail server
  21. $Parser->setStream(fopen("php://stdin", "r"));
  22.  
  23. // Once we've indicated where to find the mail, we can parse out the data
  24. $to = $Parser->getHeader('to'); // "test" <test@example.com>, "test2" <test2@example.com>
  25. $addressesTo = $Parser->getAddresses('to'); //Return an array : [["display"=>"test", "address"=>"test@example.com", false],["display"=>"test2", "address"=>"test2@example.com", false]]
  26.  
  27. $from = $Parser->getHeader('from'); // "test" <test@example.com>
  28. $addressesFrom = $Parser->getAddresses('from'); //Return an array : [["display"=>"test", "address"=>"test@example.com", "is_group"=>false]]
  29.  
  30. $subject = $Parser->getHeader('subject');
  31.  
  32. $text = $Parser->getMessageBody('text');
  33.  
  34. $html = $Parser->getMessageBody('html');
  35. $htmlEmbedded = $Parser->getMessageBody('htmlEmbedded'); //HTML Body included data
  36.  
  37. $stringHeaders = $Parser->getHeadersRaw(); // Get all headers as a string, no charset conversion
  38. $arrayHeaders = $Parser->getHeaders(); // Get all headers as an array, with charset conversion
  39.  
  40. // Pass in a writeable path to save attachments
  41. $attach_dir = '/path/to/save/attachments/'; // Be sure to include the trailing slash
  42. $include_inline = true; // Optional argument to include inline attachments (default: true)
  43. $Parser->saveAttachments($attach_dir [,$include_inline]);
  44.  
  45. // Get an array of Attachment items from $Parser
  46. $attachments = $Parser->getAttachments([$include_inline]);
  47.  
  48. // Loop through all the Attachments
  49. if (count($attachments) > 0) {
  50. foreach ($attachments as $attachment) {
  51. echo 'Filename : '.$attachment->getFilename().'<br />'; // logo.jpg
  52. echo 'Filesize : '.filesize($attach_dir.$attachment->getFilename()).'<br />'; // 1000
  53. echo 'Filetype : '.$attachment->getContentType().'<br />'; // image/jpeg
  54. echo 'MIME part string : '.$attachment->getMimePartStr().'<br />'; // (the whole MIME part of the attachment)
  55. }
  56. }
  57.  
  58. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement