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

66 lines
1.2 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
{
private $conf;
function __construct ($db)
{
$this->conf = $db->getObject (
2017-12-20 11:34:04 +00:00
'SELECT host, port, secure, sender, senderName, user, password
FROM hedera.mailConfig'
);
}
function createObject ($mailTo, $body, $subject)
{
$conf = $this->conf;
$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;
}
2017-12-20 11:34:04 +00:00
$mail->setFrom ($conf->sender, $conf->senderName);
$mail->IsHTML (TRUE);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->CharSet = 'UTF-8';
2017-04-24 13:50:05 +00:00
$mailList = explode (',', $mailTo);
foreach ($mailList as $to)
$mail->AddAddress ($to);
return $mail;
}
function send ($mailTo, $body, $subject)
{
$mail = $this->createObject ($mailTo, $body, $subject);
if (!$mail->Send ())
throw new UserException ('Send error: '.$mail->ErrorInfo);
}
}