Commit ed767e0f authored by Thomas Bella's avatar Thomas Bella

Create PHPMailer class once per domain and not one per notification

parent 835947a5
Pipeline #315 passed with stage
in 16 seconds
......@@ -253,32 +253,34 @@ foreach ($ressources as $row) {
if ($days !== false) {
$SQL->query("UPDATE log SET notification_step = :notstep WHERE domain_id = :id", [ "notstep" => $index, "id" => $row["id"] ]);
foreach ($emailList as $singleEmail) {
vlog('Sending expiration EMail to ' . $singleEmail, 2);
$mail = new PHPMailer;
if (EMAIL_SMTP) {
$mail->isSMTP();
$mail->Host = EMAIL_HOST;
$mail->Port = EMAIL_PORT;
$mail->SMTPSecure = EMAIL_ENCRYPT;
if (EMAIL_SMTPAUTH == true) {
$mail->SMTPAuth = true;
$mail->Username = EMAIL_USERNAME;
$mail->Password = EMAIL_PASSWORD;
}
$mail = new PHPMailer;
if (EMAIL_SMTP) {
$mail->isSMTP();
$mail->SMTPKeepAlive = true;
$mail->Host = EMAIL_HOST;
$mail->Port = EMAIL_PORT;
$mail->SMTPSecure = EMAIL_ENCRYPT;
if (EMAIL_SMTPAUTH == true) {
$mail->SMTPAuth = true;
$mail->Username = EMAIL_USERNAME;
$mail->Password = EMAIL_PASSWORD;
}
}
$mail->setFrom(EMAIL_FROM, 'Certificate Monitor');
$mail->addAddress($singleEmail);
$mail->Subject = 'Certificate Monitor [' . $row['domain'] . ']';
$mail->Body = 'Your certificate for ' . $row['domain'] . ':' . $row['port'] . ' will expire in about ' . $days . ' days (' . date("d.m.Y H:i", $expiryDate) . ').' . "\n" .
'Please renew your certificate.' . "\n\n" . 'Certificate Monitor on ' . BASEURL;
$mail->setFrom(EMAIL_FROM, 'Certificate Monitor');
$mail->Subject = 'Certificate Monitor [' . $row['domain'] . ']';
// TODO: Use port class to print protocol instead/in addition to port
$mail->Body = 'Your certificate for ' . $row['domain'] . ':' . $row['port'] . ' will expire in about ' . $days . ' days (' . date("d.m.Y H:i", $expiryDate) . ').' . "\n" .
'Please renew your certificate.' . "\n\n" . 'Certificate Monitor on ' . BASEURL;
foreach ($emailList as $singleEmail) {
vlog('Sending EMail to ' . $singleEmail, 2);
$mail->addAddress($singleEmail);
if (!$mail->send()) {
vlog($mail->ErrorInfo, 2);
}
$mail->clearAddresses();
}
} // $days not false
} // EMAIL enabled
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment