Blog Sections Open
Sending FormLister Submissions to Telegram
Use a prepare snippet to forward FormLister submissions to Telegram in a clean, maintainable way.
FormLister can do more than send mail. A small prepare snippet is enough to forward form submissions to a Telegram bot, which is useful for quick notifications on landing pages, internal dashboards, and compact client projects.
The right overall idea is simple: collect the form fields, build a readable message, and send it to the Telegram Bot API. The main cleanup is making the request safer and easier to maintain.
Prepare snippet example
<?php
$token = 'YOUR_BOT_TOKEN';
$chatId = 'YOUR_CHAT_ID';
$ip = $modx->getOption('REMOTE_ADDR', $_SERVER, '');
$name = $FormLister->getField('name');
$email = $FormLister->getField('email');
$message = $FormLister->getField('message');
$rows = [
'Name' => $name,
'Email' => $email,
'Message' => $message,
'IP' => $ip,
];
$text = '';
foreach ($rows as $label => $value) {
$text .= '<b>' . $label . '</b>: ' . $value . "
";
}
file_get_contents(
'https://api.telegram.org/bot' . $token . '/sendMessage?' . http_build_query([
'chat_id' => $chatId,
'parse_mode' => 'html',
'text' => $text,
])
);
return true;
What to improve from the original pattern
- use
http_build_query()instead of building the URL manually - store the bot token and chat ID in configuration, not inside the snippet body
- sanitize or limit very long message fields before sending them to Telegram
This approach is a good fit when the site owner wants instant chat notifications and does not need a full CRM integration yet. It is especially useful for lead forms where email delivery may be slower or less visible than a Telegram alert.
Passing Placeholder Values into a Custom Snippet
A small debugging guide for passing placeholder output into custom snippets and avoiding empty values caused by parser timing or quoting mistakes.
Hiding DLcrumbs Items That Should Not Appear in Menus
A breadcrumb note for cases where items hidden from menus should also be excluded from the breadcrumb trail.