Last active
January 23, 2017 12:41
-
-
Save EvilWolf/a4e9ff2620e95f71cb7b to your computer and use it in GitHub Desktop.
Bitrix SMTP
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
<?php | |
function custom_mail($to, $subject, $message, $additional_headers, $additional_parameters) { | |
require_once(__DIR__ . '/vendor/PHPMailer/PHPMailerAutoload.php'); | |
/* Парсинг дополнительных заголовков в письмах. */ | |
$additional_headers_array = explode("\n", $additional_headers); | |
$arHeaders = array(); | |
foreach ($additional_headers_array as $key => $value) { | |
$arTmp = explode(':', $value); | |
$arHeaders[$arTmp[0]] = $arTmp[1]; | |
} | |
if ($arHeaders['BCC']) { | |
$arHeaders['BCC'] = explode(',', trim($arHeaders['BCC'])); | |
} | |
unset($additional_headers_array); | |
/* Настройки smtp */ | |
$smtp = array( | |
'host' => 'smtp.yandex.ru', | |
'user' => 'testsmtp@domain.com', | |
'password' => '#password#', | |
'from' => 'testsmtp@domain.com', | |
'fromName' => 'SMTP From', | |
'port' => 465, | |
'debug' => 0, | |
'ssl' => true | |
); | |
$to = str_replace(' ','', $to); | |
$mail = new PHPMailer(); | |
$mail->IsSMTP(); | |
$mail->CharSet = 'UTF-8'; | |
$mail->Host = $smtp['host']; // SMTP server example | |
$mail->SMTPDebug = $smtp['debug']; // enables SMTP debug information (for testing) | |
$mail->Timeout = 10; | |
$mail->SMTPAuth = true; // enable SMTP authentication | |
$mail->Port = $smtp['port']; // set the SMTP port for the GMAIL server | |
$mail->Username = $smtp['user']; // SMTP account username example | |
$mail->Password = $smtp['password']; // SMTP account password example | |
$mail->From = $smtp['from']; | |
$mail->FromName = $smtp['fromName']; | |
if ($smtp['ssl']) { | |
$mail->SMTPSecure = "ssl"; | |
} | |
$address = explode(',', $to); | |
foreach ($address as $addr) { | |
$mail->addAddress($addr); | |
} | |
if (count($arHeaders['BCC'])) { | |
foreach ($arHeaders['BCC'] as $bcc_email) { | |
$mail->AddBCC(trim($bcc_email)); | |
} | |
} | |
if (substr_count($additional_headers, "Content-Type: text/html")) { | |
$mail->isHTML(true); // Set email format to HTML | |
} | |
$mail->Subject = $subject; | |
$mail->Body = $message; | |
if (!$mail->send()) { | |
echo "Message could not be sent. <p>"; | |
echo "Mailer Error: " . $mail->ErrorInfo; | |
$return = false; | |
} else { | |
$return = true; | |
} | |
return $return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment