42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
use PHPMailer\PHPMailer\Exception;
|
|
|
|
function sendmail($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();
|
|
|
|
} |