Sendersy + MODX

MODX Revolution + Sendersy: a PHP snippet you call from chunks or FormIt hooks.

1. Install

bash
# 1) Create a snippet "sendersyMail" in Elements
# 2) Call it from FormIt → &hooks=`sendersyMail`

2. Environment variables

bash
// MODX → System Settings → create setting
// key:   sendersy.api_key
// value: sk_live_...

3. Send an email

php
<?php
/**
 * MODX snippet: sendersyMail
 * Use with FormIt:  &hooks=`sendersyMail`
 * Reads &emailTo, &emailSubject, &emailTpl placeholders from FormIt.
 */
$apiKey = $modx->getOption('sendersy.api_key');
if (!$apiKey) {
    $hook->addError('sendersy', 'SENDERSY_API_KEY not configured');
    return false;
}

$values   = $hook->getValues();
$to       = $modx->getOption('emailTo',      $scriptProperties, $values['email'] ?? '');
$subject  = $modx->getOption('emailSubject', $scriptProperties, 'New submission');
$tplName  = $modx->getOption('emailTpl',     $scriptProperties, '');
$bodyHtml = $tplName
    ? $modx->getChunk($tplName, $values)
    : '<pre>' . htmlspecialchars(print_r($values, true)) . '</pre>';

$ch = curl_init('https://api.sendersy.com/v1/emails');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST           => true,
    CURLOPT_HTTPHEADER     => [
        'Authorization: Bearer ' . $apiKey,
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'from'    => 'MODX site <noreply@yourdomain.com>',
        'to'      => [$to],
        'subject' => $subject,
        'html'    => $bodyHtml,
        'tags'    => [['name' => 'source', 'value' => 'modx']],
    ]),
]);
$resp = curl_exec($ch);
curl_close($ch);

return $resp ? true : false;

Ready to start?

Get your API key in 30 seconds.

Sign up