Files
anpdf/app/routes/email.php
arlemp@selectel.ru 47947dd13e correct text main
2025-03-11 22:04:36 +03:00

87 lines
2.4 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
function sendmail($config, $mail) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$send = new PHPMailer(true);
try {
//$send->SMTPDebug = 2; // Включить отладку
//$send->Debugoutput = 'html';
$send->isSMTP();
$send->Host = 'mail.argumenti.ru';
$send->SMTPAuth = true;
$send->CharSet = 'UTF-8';
$send->Username = 'klan@mail.argumenti.ru';
$send->Password = 'Adfhj789-jkhgk6F';
$send->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$send->Port = 587;
$send->setFrom('klan@mail.argumenti.ru', 'Аргументы Недели');
$send->addAddress($mail['mail'], $mail['mail']);
if (isset($mail['html'])) {
$send->isHTML(true);
} else {
$send->ContentType = 'text/plain';
$send->isHTML(false);
}
$send->Subject = $mail['subject'];
$send->Body = $mail['message'];
return $send->send();
} catch (Exception $e) {
//echo "Ошибка отправки: {$e->getMessage()}";
echo '<p>К сожалению в данный момент письмо невозможно отправить.</p><p>Попробуйте позже.</p>';
}
}
function sendmail_old($config, $mail){
$send = new PHPMailer;
$send->isSMTP();
//$send->SMTPDebug=3; // Set mailer to use SMTP
$send->Host = $config['host']; // Specify main and backup SMTP servers
$send->Username = $config['login']; // SMTP username
$send->Password = $config['password'];
if (isset($config['secure'])) {
$send->SMTPSecure = $config['secure'];
$send->SMTPAuth = true;
}
else {
$send->SMTPSecure = false;
$send->SMTPAutoTLS = false;
}
$send->Port = $config['port']; // TCP port to connect to
$send->setFrom($config['login'], $config['name']);
$send->addAddress($mail['mail'], $mail['mail']); // Add a recipient
$send->CharSet = 'UTF-8';
if (isset($mail['html'])){
$send->isHTML(True); // Set email format to HTML
}
else {
$send->ContentType = 'text/plain';
$send->isHTML(False);
}
$send->Subject = $mail['subject'];
$send->Body = $mail['message'];
return $send->send();
}