0
1
Fork 0
hedera-web-mindshore/web/mailer.php

54 lines
1.0 KiB
PHP
Raw Normal View History

<?php
namespace Vn\Web;
2016-10-17 06:52:14 +00:00
require_once 'libphp-phpmailer/PHPMailerAutoload.php';
use Vn\Lib\UserException;
class Mailer
{
static function send ($db, $mailTo, $body, $subject)
{
$conf = $db->getRow (
'SELECT host, port, secure, sender, sender_name, user, password
FROM mail_config'
);
$mail = new \PHPMailer ();
$mail->isSMTP ();
$mail->Host = $conf['host'];
if (!empty ($conf['user']))
{
$mail->SMTPAuth = TRUE;
$mail->Username = $conf['user'];
$mail->Password = base64_decode ($conf['password']);
}
else
$mail->SMTPAuth = FALSE;
if ($conf['secure'])
{
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
}
$mail->setFrom ($conf['sender'], $conf['sender_name']);
2017-04-24 13:50:05 +00:00
$mailList = explode (',', $mailTo);
foreach ($mailList as $to)
$mail->AddAddress ($to);
$mail->IsHTML (TRUE);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->CharSet = 'UTF-8';
if (!$mail->Send ())
throw new UserException ('Send error: '.$mail->ErrorInfo);
}
}