konratnox
1/12/2017 - 12:44 PM

Отправка почты через smtp

Отправка почты через smtp

//другой вариант

function custom_mail($to, $subject, $message, $additional_headers, $additional_parameters) {
    require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/custom_classes/PHPMailerAutoload.php');

    $mail = new PHPMailer;
    $mail->isSMTP();
    $mail->CharSet = 'utf-8';
    $mail->Host = "smtp.yandex.ru";
    $mail->Port = 465;
    $mail->SMTPAuth = true;
    $mail->Username = 'info@xn----ftbnbajbitbe8an4aa5b5j.xn--p1ai';
    $mail->Password = 'ТУТ ВАШ ПАРОЛЬ';
    $mail->SMTPSecure = 'ssl';

    $mail->setFrom('info@xn----ftbnbajbitbe8an4aa5b5j.xn--p1ai');
    $mail->addReplyTo('info@xn----ftbnbajbitbe8an4aa5b5j.xn--p1ai');
    $emailsTo = explode(',', $to);
    foreach ($emailsTo as $email) {
        $mail->addAddress($email);
    }
    $mail->isHTML(true);

    if ($additional_headers) {
        $additional_headers = explode("\n", $additional_headers);
        $arrHeaders = array();

        foreach ($additional_headers as $header) {
            $header = explode(": ", $header);

            $arrHeaders[$header[0]] = $header[1];
            if ($header[0] == 'BCC')
                $header[1] = explode(',', $header[1]);
                foreach ($header[1] as $emailBBC)
                    $mail->addBCC($emailBBC);
            if ($header[0] == 'CC')
                $header[1] = explode(',', $header[1]);
                foreach ($header[1] as $emailCC)
                    $mail->addCC($emailCC);
        }
    }

    $message = str_replace(array("\r\n", "\r", "\n"), "<br />", $message);
    $mail->Subject = $subject;
    $mail->Body    = $message;

    if (!$mail->send()) {
        file_put_contents($_SERVER['DOCUMENT_ROOT'].'/mail.log', "Mailer Error: " . $mail->ErrorInfo, FILE_APPEND);
    } else {
        return true;
    }
}