50 lines
993 B
PHP
Executable File
50 lines
993 B
PHP
Executable File
<?php
|
|
|
|
namespace Vn\Web;
|
|
|
|
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']);
|
|
$mail->AddAddress ($mailTo);
|
|
|
|
$mail->IsHTML (TRUE);
|
|
$mail->Subject = $subject;
|
|
$mail->Body = $body;
|
|
$mail->CharSet = 'UTF-8';
|
|
|
|
if (!$mail->Send ())
|
|
throw new UserException ('Send error: '.$mail->ErrorInfo);
|
|
}
|
|
}
|
|
|