The PHPMailer plugin enhances email sending capabilities in Cotonti Siena by integrating the PHPMailer library (version 6.10.0). It replaces the default cot_mail function with a robust SMTP-based solution, adding advanced features like plugin isolation, duplicate prevention, and detailed logging. This plugin is designed for developers who need fine-grained control over email notifications in Cotonti, particularly for plugins like comments and contact.
- Uses PHPMailer 6.10.0 to send emails via SMTP, supporting modern email servers with authentication and encryption (SSL/TLS).
- Configurable SMTP settings (host, port, username, password, etc.) through the Cotonti admin panel.
- Does not require Composer; all dependencies are included.
- Allows selective disabling of email sending for specific plugins (e.g.,
comments,contact). - Controlled via the
$enable_plugin_isolationsetting and$isolated_pluginsarray. - Useful for preventing unwanted notifications (e.g., disabling comment notifications for admins).
- Relies on Cotonti's
$env['ext']to identify the calling plugin, with fallback to 'unknown' if not set.
- Supports multiple recipient formats:
- Single email string (e.g.,
user2025nick.demo@domain.ltd). - Array of emails (e.g.,
['user2025nick.demo@domain.ltd', 'admin2025.demo@domain.ltd']). - Complex arrays from plugins like
contact(e.g.,['to' => 'support.demo@domain.ltd', 'from' => ['user2025nick.demo@domain.ltd', 'test_user']]).
- Single email string (e.g.,
- Validates email addresses using
filter_var(FILTER_VALIDATE_EMAIL)to prevent errors. - Ignores invalid or non-email entries, ensuring robust handling.
- Prevents duplicate emails using two mechanisms:
- Full message key (
$mail_key): Based on recipient, subject, and body (MD5 hash). Blocks identical emails. - Recipient-subject key (
$recipient_key): Blocks emails to the same recipient with the same subject within 60 seconds.
- Full message key (
- Uses a global
$cot_mail_processedarray to track sent emails during the request.
- Logs all email attempts to
plugins/phpmailer/logs/phpmailer.log(if enabled):- Includes
Request ID, recipient, subject, plugin, request URI, GET/POST params, and a shortened email body. - Logs skips due to plugin isolation or duplicate prevention.
- Includes
- SMTP debug logging to
plugins/phpmailer/logs/phpmailer_debug.log(if enabled):- Captures detailed SMTP interactions (e.g., connection, authentication).
- Logging is configurable via
$enable_main_loggingand$enable_debug_logging.
- Applies Cotonti email templates (
$cfg['subject_mail'],$cfg['body_mail']) if no custom template is specified. - Substitutes variables like
SITE_TITLE,SITE_URL,MAIL_SUBJECT, andMAIL_BODY. - Ensures proper UTF-8 encoding for subjects using
mb_encode_mimeheader.
- Gracefully handles invalid recipients, SMTP errors, and configuration issues.
- Logs errors to both the plugin log and Cotonti’s system log (
cot_log). - Returns appropriate boolean values (
truefor success or skipped emails,falsefor failures) to maintain compatibility with Cotonti plugins.
- Tested with PHP 8.2 and Cotonti Siena v0.9.26.
- Avoids strict type issues and handles array-to-string conversions safely.
-
Download the Plugin
- Clone or download this repository to your Cotonti installation’s
plugins/directory.
- Clone or download this repository to your Cotonti installation’s
-
Directory Structure
- Ensure the following structure:
plugins/phpmailer/ ├── phpmailer.global.php ├── phpmailer.setup.php ├── src/ │ ├── PHPMailer.php │ ├── SMTP.php │ ├── Exception.php ├── lang/ │ ├── phpmailer.en.lang.php │ ├── phpmailer.ru.lang.php ├── logs/ │ ├── phpmailer.log (created automatically) │ ├── phpmailer_debug.log (created automatically)
- Ensure the following structure:
-
Set Permissions
- Ensure the
plugins/phpmailer/logs/directory is writable:chmod 0755 plugins/phpmailer/logs chmod 0644 plugins/phpmailer/logs/*.log - The web server user (e.g.,
www-data) must have write access.
- Ensure the
-
Activate the Plugin
- Go to the Cotonti admin panel (
Administration > Extensions). - Find
phpmailerand activate it.
- Go to the Cotonti admin panel (
-
SMTP Settings
- In the Cotonti admin panel, go to
Administration > Extensions > PHPMailer > Configure. - Set the following:
Host: SMTP server (e.g.,smtp.gmail.com).Port: SMTP port (e.g.,587for TLS).SMTPAuth: Enable/disable authentication (true/false).SMTPSecure: Encryption type (tlsorssl).Username: SMTP username (e.g.,sender.demo@domain.ltd).Password: SMTP password.from_author: Sender email (e.g.,no-reply.demo@domain.ltd).from_name: Sender name (e.g.,Demo Site).reply: Reply-to email (optional, e.g.,reply.demo@domain.ltd).reply_name: Reply-to name (optional).
- In the Cotonti admin panel, go to
-
Plugin Settings
- Edit
plugins/phpmailer/phpmailer.global.phpto configure:$enable_plugin_isolation: Set totrueto enable isolation for specified plugins.$isolated_plugins: Array of plugins to isolate (e.g.,['comments', 'contact']).$enable_main_logging: Set totrueto enable logging tophpmailer.log.$enable_debug_logging: Set totrueto enable SMTP debug logging.$mail->SMTPDebug: Set to1or higher for verbose SMTP debug output (requires$enable_debug_logging = true).
Example:
$enable_plugin_isolation = true; // Enable isolation $isolated_plugins = ['comments', 'contact']; // Isolate comments and contact plugins $enable_main_logging = true; // Enable main log $enable_debug_logging = true; // Enable debug log $mail->SMTPDebug = 1; // Basic SMTP debug output
- Edit
- To prevent emails from specific plugins:
- Set
$enable_plugin_isolation = true. - Add plugin names to
$isolated_plugins(e.g.,['comments', 'contact']).
- Set
- Emails from these plugins will be skipped, with a log entry:
[2025-05-07 12:00:00] Request ID: 123abc, Email to support.demo@domain.ltd skipped due to plugin isolation (plugin: contact).
- Enable logging for debugging:
- Set
$enable_main_logging = trueto log email attempts and results. - Set
$enable_debug_logging = trueand$mail->SMTPDebug = 1for SMTP details.
- Set
- Logs are stored in
plugins/phpmailer/logs/:phpmailer.log: General email activity (attempts, successes, skips).phpmailer_debug.log: SMTP debug output.
- Example log entry:
[2025-05-07 12:00:00] Request ID: 123abc, Attempt to send email to: {"to":"support.demo@domain.ltd","from":["user2025nick.demo@domain.ltd","test_user"]}, Subject: Dropped, HTML: false, Plugin: contact, Request URI: /contact, GET: {"rwr":"contact","e":"contact"}, POST: {...}, Body (short): Demo Site - https://demo.domain.ltd [2025-05-07 12:00:00] Request ID: 123abc, Successfully sent email to support.demo@domain.ltd
- Automatically blocks:
- Identical emails (same recipient, subject, body).
- Emails to the same recipient with the same subject within 60 seconds.
- Logged as:
[2025-05-07 12:00:00] Request ID: 123abc, Email to support.demo@domain.ltd with recipient key 1f6e555fafe32cbfb7a311fbf9e83f3e blocked due to recent send.
- The plugin handles complex
$fmailarrays from plugins likecontact:$fmail = ['to' => 'support.demo@domain.ltd', 'from' => ['user2025nick.demo@domain.ltd', 'test_user']];
- Extracts valid emails from
$fmail['to'], ignores$fmail['from'].
- Check SMTP Settings: Verify
Host,Port,Username,Passwordin the admin panel. - Enable Logging: Set
$enable_main_logging = true,$enable_debug_logging = true,$mail->SMTPDebug = 1, and checkphpmailer.logandphpmailer_debug.log. - Isolation: Ensure
$enable_plugin_isolation = falseor the plugin is not in$isolated_plugins.
- If an admin receives multiple emails (e.g., for comments):
- Check if multiple admins are in
COT_GROUP_SUPERADMINS(normal behavior). - Enable
$enable_main_logging = trueand inspectRequest IDandMail Keyinphpmailer.log. - Reduce the duplicate timeout (e.g., from 60 to 10 seconds):
if (time() - $last_sent < 10) { ... }
- Check if multiple admins are in
- Verify permissions:
Ensure 0644 for log files and 0755 for the directory.
ls -l plugins/phpmailer/logs
- Check
$enable_main_loggingand$enable_debug_loggingaretrue. - Check
error_logfor redirected logs:tail -n 50 /var/log/apache2/error.log
- If
$env['ext']returns 'unknown' for a plugin, add a fallback filter based on email body:if ($enable_plugin_isolation && (in_array($context['plugin'], $isolated_plugins) || strpos($body, 'оставил Комментарий к странице') !== false)) { log_phpmailer_file("Request ID: $request_id, Email to $fmail_log skipped due to plugin isolation or comment content."); return true; }
- Cotonti: Siena v0.9.26 (tested; may work with other versions, but not guaranteed).
- PHP: 8.2 (tested; compatible with 7.x, but test before use).
- PHPMailer: Version 6.10.0 (included, no Composer required).
- Fork the repository, make changes, and submit a pull request.
- Report issues or suggest features via GitHub Issues.
- MIT License (see
LICENSEfile).
- Built for the CleanCot project.
- Based on PHPMailer 6.10.0 by PHPMailer.
- Developed with love for the Cotonti CMF ❤️.
-
Userarticles for CMF Cotonti The plugin for CMF Cotonti displays a list of users with the number of their articles and a detailed list of articles for each user.
-
Export to Excel via PhpSpreadsheet for CMF Cotonti Exporting Articles to Excel from the Database in Cotonti via PhpSpreadsheet.Composer is not required for installation.
-
Import from Excel via PhpSpreadsheet for CMF Cotonti The plugin for importing articles from Excel for all Cotonti-based websites.Composer is not required for installation.
-
SeoArticle Plugin for Cotonti The SeoArticle plugin enhances the SEO capabilities of the Cotonti CMF's Pages module by adding meta tags, Open Graph, Twitter Card, Schema.org structured data, keyword extraction, reading time estimation, and related articles functionality.
-
CleanCot Theme for Cotonti The CleanCot theme for CMF Cotonti. Modern Bootstrap theme on v.5.3.3 for Cotonti Siena v.0.9.26 without outdated (legacy) mode. Only relevant tags!
Плагин PHPMailer улучшает функционал отправки email в Cotonti Siena, интегрируя библиотеку PHPMailer (версия 6.10.0). Он заменяет стандартную функцию cot_mail на мощное решение на основе SMTP, добавляя продвинутые возможности, такие как изоляция плагинов, защита от дублирования писем и детальное логирование. Плагин создан для разработчиков, которым нужен точный контроль над email-уведомлениями в Cotonti, особенно для плагинов comments и contact.
- Использует PHPMailer 6.10.0 для отправки писем через SMTP, поддерживая современные почтовые серверы с аутентификацией и шифрованием (SSL/TLS).
- Настраиваемые параметры SMTP (хост, порт, имя пользователя, пароль и т.д.) через админ-панель Cotonti.
- Не требует Composer; все зависимости включены в плагин.
- Позволяет выборочно отключать отправку писем для определённых плагинов (например,
comments,contact). - Управляется через настройку
$enable_plugin_isolationи массив$isolated_plugins. - Полезно для предотвращения нежелательных уведомлений (например, отключение уведомлений о комментариях для админов).
- Использует переменную Cotonti
$env['ext']для определения вызывающего плагина, с возвратом 'unknown', если плагин не определён.
- Поддерживает несколько форматов получателей:
- Одиночный email (например,
user2025nick.demo@domain.ltd). - Массив email’ов (например,
['user2025nick.demo@domain.ltd', 'admin2025.demo@domain.ltd']). - Сложные массивы от плагинов, таких как
contact(например,['to' => 'support.demo@domain.ltd', 'from' => ['user2025nick.demo@domain.ltd', 'test_user']]).
- Одиночный email (например,
- Проверяет email-адреса с помощью
filter_var(FILTER_VALIDATE_EMAIL)для исключения ошибок. - Игнорирует некорректные или не-email элементы, обеспечивая надёжную работу.
- Предотвращает отправку дублирующихся писем с помощью двух механизмов:
- Ключ полного сообщения (
$mail_key): Основан на получателе, теме и теле письма (хэш MD5). Блокирует одинаковые письма. - Ключ получатель-тема (
$recipient_key): Блокирует письма одному получателю с той же темой в течение 60 секунд.
- Ключ полного сообщения (
- Использует глобальный массив
$cot_mail_processedдля отслеживания отправленных писем в рамках запроса.
- Записывает все попытки отправки писем в
plugins/phpmailer/logs/phpmailer.log(если включено):- Включает
Request ID, получателя, тему, плагин, URI запроса, параметры GET/POST и укороченное тело письма. - Логирует пропуски из-за изоляции плагинов или дублирования.
- Включает
- Отладочное логирование SMTP в
plugins/phpmailer/logs/phpmailer_debug.log(если включено):- Фиксирует подробности SMTP-взаимодействия (например, подключение, аутентификация).
- Логирование настраивается через
$enable_main_loggingи$enable_debug_logging.
- Применяет шаблоны писем Cotonti (
$cfg['subject_mail'],$cfg['body_mail']), если не указан кастомный шаблон. - Подставляет переменные, такие как
SITE_TITLE,SITE_URL,MAIL_SUBJECT,MAIL_BODY. - Обеспечивает корректное кодирование тем в UTF-8 с помощью
mb_encode_mimeheader.
- Корректно обрабатывает некорректных получателей, ошибки SMTP и проблемы с конфигурацией.
- Логирует ошибки в лог плагина и системный лог Cotonti (
cot_log). - Возвращает соответствующие булевы значения (
trueдля успешной отправки или пропуска,falseдля ошибок), сохраняя совместимость с плагинами Cotonti.
- Протестирован с PHP 8.2 и Cotonti Siena v0.9.26.
- Избегает проблем со строгими типами и безопасно обрабатывает преобразование массивов в строки.
-
Скачивание плагина
- Клонируйте или скачайте репозиторий в директорию
plugins/вашей установки Cotonti.
- Клонируйте или скачайте репозиторий в директорию
-
Структура директорий
- Убедитесь, что структура следующая:
plugins/phpmailer/ ├── phpmailer.global.php ├── phpmailer.setup.php ├── src/ │ ├── PHPMailer.php │ ├── SMTP.php │ ├── Exception.php ├── lang/ │ ├── phpmailer.en.lang.php │ ├── phpmailer.ru.lang.php ├── logs/ │ ├── phpmailer.log (создаётся автоматически) │ ├── phpmailer_debug.log (создаётся автоматически)
- Убедитесь, что структура следующая:
-
Установка прав доступа
- Убедитесь, что директория
plugins/phpmailer/logs/доступна для записи:chmod 0755 plugins/phpmailer/logs chmod 0644 plugins/phpmailer/logs/*.log - Пользователь веб-сервера (например,
www-data) должен иметь права на запись.
- Убедитесь, что директория
-
Активация плагина
- Зайдите в админ-панель Cotonti (
Администрирование > Расширения). - Найдите
phpmailerи активируйте его.
- Зайдите в админ-панель Cotonti (
-
Настройки SMTP
- В админ-панели Cotonti перейдите в
Администрирование > Расширения > PHPMailer > Настроить. - Установите следующие параметры:
Host: SMTP-сервер (например,smtp.gmail.com).Port: Порт SMTP (например,587для TLS).SMTPAuth: Включить/отключить аутентификацию (true/false).SMTPSecure: Тип шифрования (tlsилиssl).Username: Имя пользователя SMTP (например,sender.demo@domain.ltd).Password: Пароль SMTP.from_author: Email отправителя (например,no-reply.demo@domain.ltd).from_name: Имя отправителя (например,Демо Сайт).reply: Email для ответа (опционально, например,reply.demo@domain.ltd).reply_name: Имя для ответа (опционально).
- В админ-панели Cotonti перейдите в
-
Настройки плагина
- Отредактируйте
plugins/phpmailer/phpmailer.global.phpдля настройки:$enable_plugin_isolation: Установитеtrueдля включения изоляции указанных плагинов.$isolated_plugins: Массив плагинов для изоляции (например,['comments', 'contact']).$enable_main_logging: Установитеtrueдля включения лога вphpmailer.log.$enable_debug_logging: Установитеtrueдля включения отладочного лога SMTP.$mail->SMTPDebug: Установите1или выше для подробного вывода отладки SMTP (требует$enable_debug_logging = true).
Пример:
$enable_plugin_isolation = true; // Включить изоляцию $isolated_plugins = ['comments', 'contact']; // Изолировать плагины comments и contact $enable_main_logging = true; // Включить основной лог $enable_debug_logging = true; // Включить отладочный лог $mail->SMTPDebug = 1; // Базовый вывод отладки SMTP
- Отредактируйте
- Чтобы предотвратить отправку писем из определённых плагинов:
- Установите
$enable_plugin_isolation = true. - Добавьте имена плагинов в
$isolated_plugins(например,['comments', 'contact']).
- Установите
- Письма из этих плагинов будут пропущены, с записью в лог:
[2025-05-07 12:00:00] Request ID: 123abc, Email to support.demo@domain.ltd skipped due to plugin isolation (plugin: contact).
- Включите логирование для отладки:
- Установите
$enable_main_logging = trueдля записи попыток и результатов отправки. - Установите
$enable_debug_logging = trueи$mail->SMTPDebug = 1для деталей SMTP.
- Установите
- Логи сохраняются в
plugins/phpmailer/logs/:phpmailer.log: Общая активность email (попытки, успехи, пропуски).phpmailer_debug.log: Детали отладки SMTP.
- Пример записи в логе:
[2025-05-07 12:00:00] Request ID: 123abc, Attempt to send email to: {"to":"support.demo@domain.ltd","from":["user2025nick.demo@domain.ltd","test_user"]}, Subject: Dropped, HTML: false, Plugin: contact, Request URI: /contact, GET: {"rwr":"contact","e":"contact"}, POST: {...}, Body (short): Демо Сайт - https://demo.domain.ltd [2025-05-07 12:00:00] Request ID: 123abc, Successfully sent email to support.demo@domain.ltd
- Автоматически блокирует:
- Одинаковые письма (тот же получатель, тема, тело).
- Письма одному получателю с той же темой в течение 60 секунд.
- Логируется как:
[2025-05-07 12:00:00] Request ID: 123abc, Email to support.demo@domain.ltd with recipient key 1f6e555fafe32cbfb7a311fbf9e83f3e blocked due to recent send.
- Плагин обрабатывает сложные массивы
$fmailот плагинов, таких какcontact:$fmail = ['to' => 'support.demo@domain.ltd', 'from' => ['user2025nick.demo@domain.ltd', 'test_user']];
- Извлекает валидные email’ы из
$fmail['to'], игнорируя$fmail['from'].
- Проверьте настройки SMTP: Убедитесь, что
Host,Port,Username,Passwordкорректны в админ-панели. - Включите логирование: Установите
$enable_main_logging = true,$enable_debug_logging = true,$mail->SMTPDebug = 1и проверьтеphpmailer.logиphpmailer_debug.log. - Изоляция: Убедитесь, что
$enable_plugin_isolation = falseили плагин не в$isolated_plugins.
- Если админ получает несколько писем (например, для комментариев):
- Проверьте, есть ли несколько админов в
COT_GROUP_SUPERADMINS(нормальное поведение). - Включите
$enable_main_logging = trueи проверьтеRequest IDиMail Keyвphpmailer.log. - Уменьшите таймаут дублирования (например, с 60 до 10 секунд):
if (time() - $last_sent < 10) { ... }
- Проверьте, есть ли несколько админов в
- Проверьте права доступа:
Убедитесь, что файлы логов имеют права 0644, а директория — 0755.
ls -l plugins/phpmailer/logs
- Проверьте, что
$enable_main_loggingи$enable_debug_loggingустановлены вtrue. - Проверьте
error_logна перенаправленные логи:tail -n 50 /var/log/apache2/error.log
- Если
$env['ext']возвращает 'unknown' для плагина, добавьте дополнительный фильтр по содержимому письма:if ($enable_plugin_isolation && (in_array($context['plugin'], $isolated_plugins) || strpos($body, 'оставил Комментарий к странице') !== false)) { log_phpmailer_file("Request ID: $request_id, Email to $fmail_log skipped due to plugin isolation or comment content."); return true; }
- Cotonti: Siena v0.9.26 (протестировано; может работать с другими версиями, но без гарантии).
- PHP: 8.2 (протестировано; совместимо с 7.x, но рекомендуется протестировать).
- PHPMailer: Версия 6.10.0 (включена, Composer не требуется).
- Форкните репозиторий, внесите изменения и отправьте pull request.
- Сообщайте о проблемах или предлагайте новые функции через GitHub Issues.
- Лицензия MIT (см. файл
LICENSE).