Advertisement
Guest User

майлер

a guest
Dec 28th, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.54 KB | None | 0 0
  1. <?php
  2.  
  3. class MailController extends \Phalcon\Mvc\Controller
  4. {
  5.     /**
  6.      * Отправка письма.
  7.      * @param $to
  8.      * @param string $subject
  9.      * @param string $message
  10.      * @param string $from
  11.      */
  12.     public function sendMail($to, $subject = '', $message = '', $from = '', $attach = array()) {
  13.         if (!$to) {
  14.             return 'Mailer Error: Не указан получатель';
  15.         }
  16.         global $config;
  17.  
  18.         $mail = new PHPMailer;
  19.         $mail->isSMTP();
  20.  
  21.         //$mail->SMTPDebug = true;
  22.         //$mail->Debugoutput = 'html';
  23.  
  24.         if ($attach != array()) {
  25.             foreach ($attach as $att) {
  26.                 $mail->addAttachment($att);
  27.             }
  28.         }
  29.  
  30.         $mail->CharSet = 'UTF-8';
  31.         $mail->Host = $config['mail']['smtp']['server'];
  32.         $mail->Port = $config['mail']['smtp']['port'];
  33.         $mail->SMTPSecure = $config['mail']['smtp']['security'];
  34.         $mail->SMTPAuth = true;
  35.         $mail->Username = $config['mail']['smtp']['username'];
  36.         $mail->Password = $config['mail']['smtp']['password'];
  37.         if ($from == '') {
  38.             $mail->setFrom($config['mail']['fromEmail'], $config['mail']['fromName']);
  39.         } else {
  40.             $mail->setFrom($from);
  41.         }
  42.  
  43.         $mail->addAddress($to);
  44.         $mail->Subject = $subject;
  45.         $mail->msgHTML($message);
  46.  
  47.         if (!$mail->send()) {
  48.             return 'Mailer Error: ' . $mail->ErrorInfo;
  49.         } else {
  50.             return 'ok';
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement