diff --git a/deploy/phpConfig/email.php b/deploy/phpConfig/email.php new file mode 100644 index 0000000000000000000000000000000000000000..8003966a752f13a7ff45bbd2d85f333c886304d6 --- /dev/null +++ b/deploy/phpConfig/email.php @@ -0,0 +1,16 @@ +<?php defined('SYSPATH') OR die('No direct access allowed.'); + +return array +( + 'default' => array( + 'host' => 'localhost', // Specify SMTP server + 'port' => '25', // TCP port to connect to + 'username' => NULL, // SMTP username + 'password' => NULL, // SMTP password + 'SMTPAuth' => false, // Enable SMTP authentication + 'SMTPSecure' => NULL, // Enable TLS encryption, `ssl` also accepted + 'from' => 'no_reply@grade.sfedu.ru', + 'fromName' => 'Grade System (Сервис БРС)', + 'enableDebug' => false // Enable verbose debug output + ), +); diff --git a/~dev_rating/application/classes/Account.php b/~dev_rating/application/classes/Account.php index 0b87b7728aa13cf3ebecdb3545e6cb61ae0b6af1..4a2e7df1766b77cea38883f8e49f9f8012f0f260 100644 --- a/~dev_rating/application/classes/Account.php +++ b/~dev_rating/application/classes/Account.php @@ -1,46 +1,5 @@ <?php -require(DOCROOT.'/modules/mail/vendor/PHPMailer/PHPMailerAutoload.php'); - -function gradeSendMail($subject, $body, $sendToEmail, $sendToName) { - $mail = new PHPMailer; - - //$mail->SMTPDebug = 3; // Enable verbose debug output - - $mail->isSMTP(); // Set mailer to use SMTP - $mail->Host = 'class.mmcs.sfedu.ru'; // Specify main and backup SMTP servers - $mail->SMTPAuth = false; // Enable SMTP authentication - $mail->Username = NULL; // SMTP username - $mail->Password = NULL; // SMTP password - $mail->SMTPSecure = NULL; // Enable TLS encryption, `ssl` also accepted - $mail->Port = 25; // TCP port to connect to - - $mail->From = 'no_reply@grade.sfedu.ru'; - $mail->FromName = 'Grade System (Сервис БРС)'; - $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); - //echo 'Mailer Error: ' . $mail->ErrorInfo; - } else { - Log::instance()->add(Log::NOTICE, 'Message has been sent'); - } -} - class Account { private static function checkTokenLifetime($creationDate) { @@ -81,15 +40,7 @@ class Account $twig->EMail = $email; $twig->Subject = $subject; - /* Kohana mailer is not working - $status = Mailer::factory() - ->headers('Content-Type', 'text/html; charset=utf-8') - ->subject($subject) - ->in_reply_to(Mailer::message_id()) - ->from('no-reply@rating.mmcs.sfedu.ru') - ->body($twig->render()) - ->send($email);*/ - gradeSendMail($subject, $twig->render(), $email, $UserFullName); + SendMail::send($subject, $twig->render(), $email, $UserFullName); } // remind password diff --git a/~dev_rating/application/classes/Controller/Handler/RequestsProcessing.php b/~dev_rating/application/classes/Controller/Handler/RequestsProcessing.php index 9090f93b51704745ee74f8fc4e80c2312ddacbf8..6930c399f28eaf4a37ce21c57c0e4dd44a9eb30c 100644 --- a/~dev_rating/application/classes/Controller/Handler/RequestsProcessing.php +++ b/~dev_rating/application/classes/Controller/Handler/RequestsProcessing.php @@ -49,13 +49,7 @@ class Controller_Handler_RequestsProcessing extends Controller_Handler { 'User' => $this->user, ])->render(); - $headers = [ - 'From: RatingSystem@no-reply.mmcs.sfedu.ru', - 'Reply-To: ' . $this->user->EMail, -// 'Content-Type: text/html; charset=UTF-8', - ]; - - mail($to, $subject, $message, implode("\n", $headers)); + SendMail::send($subject, $message, $to, $to); $data['success'] = ($ticket > 0); $this->response->body(json_encode($data)); diff --git a/~dev_rating/application/classes/SendMail.php b/~dev_rating/application/classes/SendMail.php new file mode 100644 index 0000000000000000000000000000000000000000..de0f5559a7ef192c28fe83eb6665ff4d933e80a4 --- /dev/null +++ b/~dev_rating/application/classes/SendMail.php @@ -0,0 +1,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'); + } + } +}