Jump to main content Jump to doc navigation

API Eletters

В версии 1.1 добавлен API для создания триггеров отправки писем по действию пользователя или из вашего сниппета/дополнения.

Пример кода сниппета

Пример сниппета: 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;

См. также

  1. Eletters.API
  2. Eletters.FormIt
  3. Eletters.Import CSV
  4. Eletters.Templates

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

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • CrewMark
  • Fabian Christen
  • Sepia River Studios
  • Dannevang Digital
  • Alex
  • A. Moreno
  • Chris Fickling
  • Stéphane Jäggi
  • Murray Wood
  • Anton Tarasov
  • JT Skaggs
  • deJaya
  • Lefthandmedia
  • eydolan
  • Following Sea
  • Guido Gallenkamp
  • YJ
  • Raffy
  • Snow Creative
  • Nick Clark
  • Guest
  • Helen
  • krisznet
  • Yanni
  • Richard

Budget

$194 per month—let's make that $500!

Learn more