Skip to content

Instantly share code, notes, and snippets.

@leotop

leotop/init.php

Forked from vadim-ontech/init.php
Created Dec 28, 2016
Embed
What would you like to do?
Bitrix custom_mail function with PHPMailer
<?
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();
}
@leotop

This comment has been minimized.

Copy link
Owner Author

@leotop leotop commented Dec 28, 2016

"/bitrix/php_interface/init.php

@leotop

This comment has been minimized.

Copy link
Owner Author

@leotop leotop commented Dec 28, 2016

You should set "return;" at the end of function. In my case, without "return;" I get a copy of mail every minute by CRON.

@leotop

This comment has been minimized.

Copy link
Owner Author

@leotop leotop commented Dec 28, 2016

Функцию можно задать в файле php_interface\dbconn.php (или init.php)

@leotop

This comment has been minimized.

Copy link
Owner Author

@leotop leotop commented Dec 28, 2016

Если хостер предоставляет альтернативные способы отправки почты с сайта, их можно использовать через функцию custom_mail. Определите эту функцию в файле /bitrix/php_interface/dbconn.php, она будет использоваться вместо встроенной mail функции с тем же набором параметров.

@GTAlex

This comment has been minimized.

Copy link

@GTAlex GTAlex commented Sep 8, 2020

error
$mail->Subject = **$title;**

adding
if(strstr($to, ',')) { $arr = preg_split("!,!", $to); foreach ($arr as $addr) { $addr = trim($addr, " \x00..\x1F"); $mail->addAddress($addr); } } else { $mail->addAddress($to); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.