Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?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');
}
}
}