Created
December 29, 2016 11:39
-
-
Save leotop/503d6a0f575fb5bea536f3cb9ca90e03 to your computer and use it in GitHub Desktop.
Битрикс отправка сообщений через smtp mail.ru с помощью phpmailer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Заменяем стандартную отправку письма | |
*/ | |
function custom_mail($to, $subject, $message, $additional_headers, $additional_parameters) { | |
$login = 'логин@mail.ru'; | |
$password = 'пароль'; | |
//парсим дополнительные заголовки в массив | |
$arHeaders = []; | |
if (!empty($additionalHeaders)) { | |
$explode = explode("\n", $additionalHeaders); | |
foreach ($explode as $strHeader) { | |
if (preg_match('/^([^\:]+)\:(.*)$/', $strHeader, $matches)) { | |
$key = trim($matches[1]); | |
$value = trim($matches[2]); | |
$arHeaders[$key] = $value; | |
} | |
} | |
} | |
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { | |
$mbEncoding = mb_internal_encoding(); | |
mb_internal_encoding('ASCII'); | |
} | |
$mail = new PHPMailer; | |
$mail->Timeout = 15; | |
$mail->isSMTP(); | |
$mail->Host = 'smtp.mail.ru'; | |
$mail->SMTPAuth = true; | |
$mail->Username = $login; | |
$mail->Password = $password; | |
$mail->SMTPSecure = 'ssl'; | |
$mail->Port = 465; | |
$mail->setFrom($login, $login); | |
foreach (array_map('trim', explode(',', $to)) as $emailTo) { | |
$mail->addAddress($emailTo); | |
} | |
//парсим копии, если есть | |
if (!empty($arHeaders['CC'])) { | |
foreach (array_map('trim', explode(',', $arHeaders['CC'])) as $emailTo) { | |
$mail->addCC($emailTo); | |
} | |
unset($arHeaders['CC']); | |
} | |
//парсим скрытые копии, если есть | |
if (!empty($arHeaders['BCC'])) { | |
foreach (array_map('trim', explode(',', $arHeaders['BCC'])) as $emailTo) { | |
$mail->addBCC($emailTo); | |
} | |
unset($arHeaders['BCC']); | |
} | |
$mail->isHTML(true); | |
$mail->Subject = $subject; | |
$mail->Body = $message; | |
$mail->AltBody = ''; | |
$result = $mail->send(); | |
if (isset($mbEncoding)) { | |
mb_internal_encoding($mbEncoding); | |
} | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment