mirror of
https://github.com/wheelybird/ldap-user-manager.git
synced 2025-01-18 23:42:54 +01:00
b33ff26fd2
* get email body from ENV * read subject from env * html mail * replace special string with username and password * missing ; * more str_replace * utf8 in mail * typo * docs * fix var * count accounts * fix print
47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?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) {
|
|
|
|
global $EMAIL, $SMTP, $log_prefix;
|
|
|
|
$mail = new PHPMailer\PHPMailer\PHPMailer();
|
|
$mail->CharSet = 'UTF-8';
|
|
$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'];
|
|
|
|
if (isset($SMTP['user'])) {
|
|
$mail->SMTPAuth = true;
|
|
$mail->Username = $SMTP['user'];
|
|
$mail->Password = $SMTP['pass'];
|
|
}
|
|
|
|
if ($MAIL['tls'] == TRUE) { $mail->SMTPSecure = "tls"; }
|
|
|
|
$mail->setFrom($EMAIL['from_address'], $EMAIL['from_name']);
|
|
$mail->addAddress($recipient_email, $recipient_name);
|
|
$mail->Subject = $subject;
|
|
$mail->Body = $body;
|
|
$mail->IsHTML(true);
|
|
|
|
if (!$mail->Send()) {
|
|
error_log("$log_prefix SMTP: Unable to send email: " . $mail->ErrorInfo);
|
|
return FALSE;
|
|
}
|
|
else {
|
|
error_log("$log_prefix SMTP: sent an email to $recipient_email ($recipient_name)");
|
|
return TRUE;
|
|
}
|
|
|
|
}
|
|
|
|
?>
|