Guest User

Untitled

a guest
Jan 14th, 2019
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) [closed]
  2. Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes)
  3.  
  4. <?php
  5. require_once 'lib/swift_required.php';
  6. $hostname = '{imap.abc.com:993/imap/ssl}INBOX';
  7. $username = 'username';
  8. $password = 'password';
  9.  
  10. $connection = imap_open($hostname,$username,$password) or die('Cannot connect to Tiriyo: ' . imap_last_error());
  11. ini_set('memory_limit', '256M');
  12.  
  13.  
  14. function Message_Parse($id)
  15.  
  16. {
  17.  
  18. global $connection;
  19.  
  20. if (is_resource($connection))
  21. {
  22. $result = array
  23. (
  24. 'text' => null,
  25. 'html' => null,
  26. 'attachments' => array(),
  27. );
  28.  
  29.  
  30. $structure = imap_fetchstructure($connection, $id, FT_UID);
  31. //print_r($structure);
  32. //array_key_exists — Checks if the given key or index exists in the array
  33. if (is_array($structure) && array_key_exists('parts', $structure))
  34. {
  35. foreach ($structure->parts as $key => $part)
  36. {
  37. if (($part->type >= 2) || (($part->ifdisposition == 1) && ($part->disposition == 'ATTACHMENT')))
  38. {
  39. $filename = null;
  40.  
  41. if ($part->ifparameters == 1)
  42. {
  43. $total_parameters = count($part->parameters);
  44.  
  45. for ($i = 0; $i < $total_parameters; $i++)
  46. {
  47. if (($part->parameters[$i]->attribute == 'NAME') || ($part->parameters[$i]->attribute == 'FILENAME'))
  48. {
  49. $filename = $part->parameters[$i]->value;
  50.  
  51. break;
  52. }
  53. }
  54.  
  55. if (is_null($filename))
  56. {
  57. if ($part->ifdparameters == 1)
  58. {
  59. $total_dparameters = count($part->dparameters);
  60.  
  61. for ($i = 0; $i < $total_dparameters; $i++)
  62. {
  63. if (($part->dparameters[$i]->attribute == 'NAME') || ($part->dparameters[$i]->attribute == 'FILENAME'))
  64. {
  65. $filename = $part->dparameters[$i]->value;
  66.  
  67. break;
  68. }
  69. }
  70. }
  71. }
  72. }
  73.  
  74. $result['attachments'][] = array
  75. (
  76. 'filename' => $filename,
  77. 'content' => str_replace(array("r", "n"), '', trim(imap_fetchbody($connection, $id, ($key + 1), FT_UID))),
  78. );
  79. }
  80.  
  81. else
  82. {
  83. if ($part->subtype == 'PLAIN')
  84. {
  85. $result['text'] = imap_fetchbody($connection, $id, ($key + 1), FT_UID);
  86. }
  87.  
  88. else if ($part->subtype == 'HTML')
  89. {
  90. $result['html'] = imap_fetchbody($connection, $id, ($key + 1), FT_UID);
  91. }
  92.  
  93. else
  94. {
  95. foreach ($part->parts as $alternative_key => $alternative_part)
  96. {
  97. if ($alternative_part->subtype == 'PLAIN')
  98. {
  99. echo '<h2>' . $alternative_part->subtype . ' ' . $alternative_part->encoding . '</h2>';
  100.  
  101. $result['text'] = imap_fetchbody($connection, $id, ($key + 1) . '.' . ($alternative_key + 1), FT_UID);
  102. }
  103.  
  104. else if ($alternative_part->subtype == 'HTML')
  105. {
  106. echo '<h2>' . $alternative_part->subtype . ' ' . $alternative_part->encoding . '</h2>';
  107.  
  108. $result['html'] = imap_fetchbody($connection, $id, ($key + 1) . '.' . ($alternative_key + 1), FT_UID);
  109. }
  110. }
  111. }
  112. }
  113. }
  114. }
  115.  
  116. else
  117. {
  118. $result['text'] = imap_body($connection, $id, FT_UID);
  119. }
  120.  
  121. $result['text'] = imap_qprint($result['text']);
  122. $result['html'] = imap_qprint(imap_8bit($result['html']));
  123.  
  124. return $result;
  125. //echo $result;
  126. }
  127.  
  128. return false;
  129. }
  130. $emails = imap_search($connection,'ALL');
  131. rsort($emails);
  132.  
  133. foreach($emails as $email_number) {
  134.  
  135. $result = Message_Parse($email_number);
  136. //print_r($structure);
  137. // echo $result['text'];
  138. //echo $result['html'];
  139. //echo $result['attachments'];
  140.  
  141. // Create the Transport
  142. $transport = Swift_MailTransport::newInstance();
  143. // Create the Mailer using your created Transport
  144. $mailer = Swift_Mailer::newInstance($transport);
  145.  
  146. // Create a message
  147. $message = Swift_Message::newInstance('Bismillahhirrahmanirraheem')
  148. ->setFrom(array('as@aaa.com' => 'jf faz'))
  149. ->setTo(array('acc@aa.com'))
  150. ->setBody($result['text'], 'Here is the message itself');
  151.  
  152. $result1 = $mailer->send($message);
  153.  
  154.  
  155. ?>
Add Comment
Please, Sign In to add comment