Add attachments to elgg_send_email ?

Hi Everyone,

How can I add ElggFile as attachments to elgg_send_email ?

Here is my sample code.

$options = [
   'relationship' => 'xxxxxxxxxxxxx',
   'relationship_guid' => 'yyyyyyy',
   'owner_guid' => 'zzzzzz',
   'inverse_relationship' => true,
   'count' => true,
   'limit' => false,
];

$count = elgg_get_entities($options);

if(!empty($count)){

   $params = array();
   unset($options['count']);
   $document = elgg_get_entities($options);
   foreach ($document as $doc) {
      $params['attachments'][] = $doc;
   }

   $options = [
      'to' => $value,
      'subject' => $subject,
      'body' => $body,
      'attachments' => $params,
  ];

   elgg_send_email(Email::factory($options));

}

The message is send, but the attachments are not sent. When I replace  elgg_send_email by notify_user ? everything works as expected and the attachments are sent.
 
Could someone help me ?
 
Regards,
 
 
 
Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking