2020-11-28 18:00:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once "/opt/PHPMailer/src/PHPMailer.php";
|
|
|
|
require_once "/opt/PHPMailer/src/SMTP.php";
|
|
|
|
require_once "/opt/PHPMailer/src/Exception.php";
|
|
|
|
|
|
|
|
function send_email($recipient_email,$recipient_name,$subject,$body) {
|
|
|
|
|
2020-11-30 16:14:53 +00:00
|
|
|
global $EMAIL, $SMTP, $log_prefix;
|
2020-11-28 18:00:01 +00:00
|
|
|
|
|
|
|
$mail = new PHPMailer\PHPMailer\PHPMailer();
|
|
|
|
$mail->isSMTP();
|
|
|
|
|
|
|
|
$mail->SMTPDebug = $SMTP['debug_level'];
|
|
|
|
$mail->Debugoutput = function($message, $level) { error_log("$log_prefix SMTP (level $level): $message"); };
|
|
|
|
|
|
|
|
$mail->Host = $SMTP['host'];
|
|
|
|
$mail->Port = $SMTP['port'];
|
2020-11-30 16:14:53 +00:00
|
|
|
|
|
|
|
if (isset($SMTP['user'])) {
|
2020-11-28 18:00:01 +00:00
|
|
|
$mail->SMTPAuth = true;
|
|
|
|
$mail->Username = $SMTP['user'];
|
|
|
|
$mail->Password = $SMTP['pass'];
|
|
|
|
}
|
|
|
|
|
2021-04-15 15:43:53 +01:00
|
|
|
if ($EMAIL['tls'] == TRUE) { $mail->SMTPSecure = "tls"; }
|
2020-11-28 18:00:01 +00:00
|
|
|
|
|
|
|
$mail->setFrom($EMAIL['from_address'], $EMAIL['from_name']);
|
|
|
|
$mail->addAddress($recipient_email, $recipient_name);
|
|
|
|
$mail->Subject = $subject;
|
|
|
|
$mail->Body = $body;
|
2020-11-30 16:14:53 +00:00
|
|
|
|
|
|
|
if (!$mail->Send()) {
|
|
|
|
error_log("$log_prefix SMTP: Unable to send email: " . $mail->ErrorInfo);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else {
|
2020-12-24 18:24:41 +00:00
|
|
|
error_log("$log_prefix SMTP: sent an email to $recipient_email ($recipient_name)");
|
2020-11-30 16:14:53 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2020-11-28 18:00:01 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|