daily pastebin goal
58%
SHARE
TWEET

bx custom_mail()

bender-nvkz Apr 27th, 2018 214 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?
  2.  
  3. /**
  4.  * Отправка писем системой, через внешний SMTP
  5.  * Функция вызывается системой автоматически, при использовании CEvent::Send()
  6.  * @param $to
  7.  * @param $subject
  8.  * @param $message
  9.  * @param $additional_headers
  10.  * @param $additional_parameters
  11.  */
  12. function custom_mail($to, $subject, $message, $additional_headers, $additional_parameters){
  13.  
  14.     require_once __DIR__ . '/vendor/PHPMailer/PHPMailerAutoload.php';
  15.     $mail = new PHPMailer;
  16.     $mail->isSMTP();
  17.     $mail->CharSet  = 'UTF-8';
  18.     $mail->setLanguage('ru');
  19.     $mail->Host = 'server.ru';
  20.     $mail->SMTPAuth = true;
  21.     $mail->Username = 'user@server.ru';
  22.     $mail->Password = 'pass';
  23.     $mail->SMTPSecure = '';
  24.     $mail->Port = 25;
  25.     $mail->From = 'user@server.ru';
  26.     $mail->FromName = 'My Name';
  27.  
  28.     $to = preg_replace('/\s+/', '', $to);
  29.     $to = explode(',', $to);
  30.     foreach ($to as $torecipient) {
  31.         $mail->addAddress($torecipient);
  32.     }
  33.  
  34.     $mail->isHTML(true);
  35.     $mail->Subject = $subject;
  36.     $mail->Body = $message;
  37.     $mail->SMTPAutoTLS = false;
  38.  
  39.     $mail->SMTPDebug = 0;
  40.  
  41.     $arr = explode("\n", $additional_headers);
  42.     if (is_array($arr)){
  43.         foreach ($arr as $key => $value) {
  44.             $arrr = explode(":", $value);
  45.             $additional_headers = $mail->HeaderLine($arrr[0], $arrr[1]);
  46.  
  47.             if($arrr[0] == 'Content-Type') $mail->ContentType = $arrr[1];
  48.             if($arrr[0] == 'BCC') {
  49.                 $arBCC = explode(",", $arrr[1]);
  50.                 foreach ($arBCC as $bccMail) {
  51.                     $mail->addBCC($bccMail);
  52.                 }
  53.             }
  54.         }
  55.     }
  56.  
  57.     if(!$mail->send()) {
  58.         //echo 'Message could not be sent.';
  59.         //echo 'Mailer Error: ' . $mail->ErrorInfo;
  60.         return false;
  61.     } else {
  62.         //echo 'Message has been sent';
  63.         return true;
  64.     }
  65.  
  66.     return null;
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top