API
Last updated Dec 7th, 2019 | Page history | Improve this page | Report an issue
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$311 per month—let's make that $500!
Learn moreEletters API¶
New in version 1.1 are easy API to create your own Triggers to send out emails via an action of the user or through your own snippet/extra.
Snippet Code example¶
Snippet Example, found at: core/components/eltters/elements/snippets/elettertriggerexample.snippet.php¶
<?php
/**
* Eletter Trigger/Response code example snippet
* @return (String) $html
*
*
* This example will just email the MODX User on page load
*
*/
if (!isset($modx->eletters)) {
$modx->addPackage('eletters', $modx->getOption('core_path').'components/eletters/model/');
$modx->eletters = $modx->getService('eletters', 'Eletters', $modx->getOption('core_path').'components/eletters/model/eletters/');
}
$eletters =& $modx->eletters;
$profile = $modx->user->getOne('Profile');
$to = $to_name = '';
if ( is_object($profile) ) {
$to = $profile->get('email');
$to_name = $profile->get('fullname');
} else {
return 'Cannot find MODX user';
}
$options = array(
'to_address' => $to,
'to_name' => $to_name,
'EResourceID' => 10,
);
$placeholders = $profile->toArray();
/**
*
* @param (Array) $options - name=>value ex: for auto response form_address=Fname Lname
* 'from_address' => '',
'from_name' => '',
'to_address' => '',
'to_name' => '',
'cc_address' => '',
'cc_name' => '',
'bcc_address' => '',
'bcc_name' => '',
'reply_to_address' => '',
'reply_to_name' => '',
'ishtml' => TRUE,
'NewsletterID' => '',
'EResourceID' => '',
'uploads' => TRUE,
'files' => TRUE,
* @param (Array) $placeholders - MODX placehoders -name=>value
* @param (Boolean) $log - TRUE will save completed email to DB
* @param (Array) $attachments - add addtional attachments
*/
$sent = $eletters->sendResponse($options, $placeholders, $log=TRUE);
$output = '';
if ( $sent ) {
$output = 'An email was sent to '.$to_name.' at '.$to.' email address.';
} else {
$output = 'An email could not be sent to '.$to_name.' at '.$to.' email address.';
}
return $output;
See Also¶
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$311 per month—let's make that $500!
Learn more