diff options
author | Andrew Dolgov <[email protected]> | 2018-11-22 22:56:50 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2018-11-22 22:56:50 +0300 |
commit | 7f31179495f4320eaa9144bc7dd16ff5947df541 (patch) | |
tree | 2ea23746e4077b16c8c2f357d1b2fbe2756f0989 /init.php |
initial
Diffstat (limited to 'init.php')
-rw-r--r-- | init.php | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/init.php b/init.php new file mode 100644 index 0000000..a347de9 --- /dev/null +++ b/init.php @@ -0,0 +1,85 @@ +<?php +class mailer_smtp extends Plugin { + private $host; + + function about() { + return array(1.0, + "Supports sending mail via SMTP using PHPMailer. Read README.txt before enabling.", + "fox", + 1); + } + + function init($host) { + $this->host = $host; + + $host->add_hook($host::HOOK_SEND_MAIL, $this); + } + + function hook_send_mail($mailer, $params) { + if (defined('SMTP_SERVER') && SMTP_SERVER) { + + $phpmailer = new PHPMailer\PHPMailer\PHPMailer(); + + $phpmailer->isSMTP(); + + $pair = explode(":", SMTP_SERVER, 2); + $phpmailer->Host = $pair[0]; + $phpmailer->Port = $pair[1]; + + if (!$phpmailer->Port) $phpmailer->Port = 25; + + if (defined('SMTP_LOGIN') && SMTP_LOGIN) { + $phpmailer->SMTPAuth = true; + $phpmailer->Username = SMTP_LOGIN; + $phpmailer->Password = SMTP_PASSWORD; + } + + if (defined('SMTP_SECURE') && SMTP_SECURE) { + $phpmailer->SMTPSecure = SMTP_SECURE; + } else { + $phpmailer->SMTPAutoTLS = false; + } + + if (defined('SMTP_SKIP_CERT_CHECKS') && SMTP_SKIP_CERT_CHECKS) { + $phpmailer->SMTPOptions = array( + 'ssl' => array( + 'verify_peer' => false, + 'verify_peer_name' => false, + 'allow_self_signed' => true + ) + ); + } + + $from_name = $params["from_name"] ? $params["from_name"] : SMTP_FROM_NAME; + $from_address = $params["from_address"] ? $params["from_address"] : SMTP_FROM_ADDRESS; + + $phpmailer->setFrom($from_address, $from_name); + $phpmailer->addAddress($params["to_address"], $params["to_name"]); + $phpmailer->Subject = $params["subject"]; + + if ($params["message_html"]) { + $phpmailer->msgHTML($params["message_html"]); + $phpmailer->AltBody = $params["message"]; + } else { + $phpmailer->Body = $params["message"]; + } + + foreach ($params['headers'] as $header) { + $phpmailer->addCustomHeader($header); + } + + $rc = $phpmailer->send(); + + if (!$rc) + $mailer->set_error($rc . " " . $phpmailer->ErrorInfo); + + return $rc; + } + } + + function api_version() { + return 2; + } + +} +?> |