<?php defined('SYSPATH') or die('No direct script access.'); require(DOCROOT.'/modules/mail/vendor/PHPMailer/PHPMailerAutoload.php'); class SendMail { public static function send($subject, $body, $sendToEmail, $sendToName) { $config = Kohana::$config->load('email.default'); $mail = new PHPMailer; if ( $config['enableDebug'] ) { $mail->SMTPDebug = 3; } $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = $config['host']; $mail->SMTPAuth = $config['SMTPAuth']; $mail->Username = $config['username']; $mail->Password = $config['password']; $mail->SMTPSecure = $config['SMTPSecure']; $mail->Port = $config['port']; $mail->From = $config['from']; $mail->FromName = $config['fromName']; $mail->addAddress($sendToEmail, $sendToName); // Add a recipient //$mail->addAddress('ellen@example.com'); // Name is optional //$mail->addReplyTo('info@example.com', 'Information'); //$mail->addCC('cc@example.com'); //$mail->addBCC('bcc@example.com'); //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name //$mail->isHTML(true); // Set email format to HTML $mail->Subject = $subject; $mail->Body = $body; //$mail->ContentType = 'text/plain'; $mail->CharSet = 'utf-8'; //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; if(!$mail->send()) { Log::instance()->add(Log::NOTICE, 'Message could not be sent: '.$mail->ErrorInfo); } else { Log::instance()->add(Log::NOTICE, 'Message has been sent'); } } }