Developing a Calculator with Email Delivery of Results in 1C-Bitrix
A calculator with email delivery is a form that computes the cost of a service or assembles a configuration, then sends the result to the user by email and to a manager for processing. The key point: sending to "the user's email" is technically trivial, but in practice it hides pitfalls — emails go to spam, the template looks like plain text from the 90s, and there is no mechanism for re-sending on delivery failure.
Calculator Architecture
A calculator on Bitrix consists of three parts:
Client-side logic (JavaScript). Reactive recalculation of values as the user changes parameters. No server dependency for the calculation itself — everything runs in the browser. This is critical for UX: the user should not have to wait for a network request while dragging a slider.
Server-side handler (PHP/Bitrix). Receives the calculation parameters, validates them, optionally fetches current data from the catalogue (prices, availability), and assembles the final data for the email. This is the layer where real prices are locked in — whatever arrives from the client can be tampered with.
Email sending system. In Bitrix this is handled by the main module with the CEvent class and mail event templates.
Mail Events in Bitrix
The correct way to send email in Bitrix is through the mail events mechanism, not directly via mail() or CEmail::Send(). This enables template editing through the administrative interface, sending logs, and queue support.
Creating an event and template:
// Register the event type (once, during installation)
CEventType::Add([
'LID' => 'ru',
'EVENT_NAME' => 'CALCULATOR_RESULT',
'NAME' => 'Calculator Result',
'DESCRIPTION' => '#RESULT_HTML# #CLIENT_EMAIL# #MANAGER_EMAIL#',
]);
// Create a mail template in Bitrix:
// Settings → Mail → Mail Templates → Add
// Send the event
CEvent::Send('CALCULATOR_RESULT', 's1', [
'CLIENT_EMAIL' => $clientEmail,
'MANAGER_EMAIL' => '[email protected]',
'RESULT_HTML' => $resultHtml,
'CALC_PARAMS' => $paramsText,
'TOTAL_PRICE' => number_format($totalPrice, 0, '.', ' ') . ' ₽',
]);
HTML Email Template
The calculator result email must be readable both on mobile and in web clients. To achieve this:
- Layout built entirely on
<table>— the only reliable approach for email clients - All styles inline (Gmail ignores
<style>in<head>) - A result table — a list of calculation parameters with the total sum highlighted
- A "Place Order" or "Contact Us" button with a link
To generate the HTML email from the calculation data, a Bitrix template is used (editable via Settings → Mail → Mail Templates) with variables such as #RESULT_HTML#, populated before calling CEvent::Send.
Delivery Problems and Solutions
Emails going to spam. Causes: sending from a domain without SPF/DKIM records, using mail() instead of SMTP, email content containing trigger words. Solution: configure SMTP via the main module (Settings → Email → SMTP) using a corporate mail server or a transactional service (SendGrid, Mailgun, Unisender).
Duplicate sends. Clicking "Get Result" multiple times or on a slow connection causes the form to be submitted multiple times. Solution: disable the button after the first click + server-side deduplication by a hash of the calculation parameters + a separate record in b_event with a check.
No send history. The standard CEvent::Send logs to b_event_log. To view the log: Settings → Diagnostics → Mail Queue. However, the log is cleared after N days by an agent. For long-term storage, save the calculation parameters and email to a dedicated highload table or a b_hl_* table in a custom HL block.
Case Study: Apartment Renovation Cost Calculator
Client — a construction company. Calculator: renovation type (cosmetic/major/designer), area, number of rooms, additional works. Result — cost range and timeline.
Task: the client receives a PDF with a detailed estimate by email; the manager receives a Telegram notification and a CRM entry.
Implementation: the server generates a PDF using the mPDF library with the company logo and a breakdown by work items. The PDF is attached to the email via CEventMessage with an attachment. In parallel — a POST request to the Telegram Bot API and a lead creation in Bitrix24 via crm.lead.add. All of this happens in a single form handler, with logging to the HL block calculator_leads.
Development Timeline
- Basic calculator + email delivery (client + manager) — 3–5 days
-
- PDF generation — +1–2 days
-
- Bitrix24 CRM integration — +1 day
-
- Telegram notifications — +0.5 days
-
- Calculation history in personal account — +2–3 days







