Last active
August 9, 2021 13:31
-
-
Save vadim-ontech/ec19074bfa7715a66339 to your computer and use it in GitHub Desktop.
Bitrix custom_mail function with 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){ | |
//Получаем тему письма | |
$elements = imap_mime_header_decode($subject); | |
$title = ''; | |
for ($i=0; $i<count($elements); $i++) { | |
$title .= $elements[$i]->text; | |
} | |
//В файле PHPMailerAutoload.php на строке 24 | |
//добавляем проверку | |
//if( !function_exists('PHPMailerAutoload') ){} | |
require_once($_SERVER['DOCUMENT_ROOT'].'/cron/phpmailer/PHPMailerAutoload.php'); | |
$mail = new PHPMailer; | |
$mail->SMTPDebug = true; | |
$mail->isSMTP(); | |
$mail->CharSet = 'UTF-8'; | |
$mail->setLanguage('ru'); | |
// Set mailer to use SMTP | |
$mail->Host = 'smtp.yandex.ru'; // Specify main and backup SMTP servers | |
$mail->SMTPAuth = true; // Enable SMTP authentication | |
$mail->Username = ''; // SMTP username | |
$mail->Password = ''; // SMTP password | |
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted | |
$mail->Port = 465; | |
$mail->From = 'email@from'; | |
$mail->FromName = 'Test'; | |
$mail->isHTML(true); | |
$mail->Subject = $text; | |
$mail->Body = $message; | |
$mail->addAddress($to); | |
if(!$mail->send()) { | |
echo $mail->ErrorInfo; | |
} | |
$mail->clearAddresses(); | |
$mail->ClearCustomHeaders(); | |
} |
https://gist.github.com/vadim-ontech/ec19074bfa7715a66339#file-init-php-L31 31 line should be $title
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should set "return;" at the end of function. In my case, without "return;" I get a copy of mail every minute by CRON.