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));
}
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by Raül Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Jerome Bakker@jeabakker

Jerome Bakker - 1 like
- Hermand Pessek@rheman

Hermand Pessek - 0 likes
You must log in to post replies.You need to add the attachments in the correct variable it should be in '$options[params][attachments]'
See https://github.com/Elgg/Elgg/blob/b20f3cb3642ecf0e69353ae286952c3fb4e62292/engine/classes/Elgg/Email.php#L101-L105
PS: just a tip if you wish to count the number of entities there is a function 'elgg_count_entities()' which takes the same options as 'elgg_get_entities()' and returns the count. Then you don't need to unset '$options[count]'
Thanks a lot @jerome it works