From 7f1d78e2cdc32f80cdef3b4c80427e59393b0a56 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Thu, 1 Jan 2026 13:40:17 +0000 Subject: [PATCH] fix issues from merging #958 - no longer provide smtp_password to smtp_mail(..) call, as it does it internally now --- functions.inc.php | 18 ++++++++---------- model/MailboxHandler.php | 2 +- public/sendmail.php | 2 +- public/users/password-recover.php | 6 +++--- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/functions.inc.php b/functions.inc.php index 38f7138b..50d1f292 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -1307,20 +1307,16 @@ function enable_socket_crypto($fh) * Call: smtp_mail (string to, string from, string data) - DEPRECATED * @param string $to * @param string $from - * @param string $subject (if called with 4 parameters) or full mail body (if called with 3 parameters) - * @param string $password (optional) - Password - * @param string $body (optional, but recommended) - mail body + * @param string $subject_or_data(if called with 4 parameters) or full mail body (if called with 3 parameters) + * @param ?string $body (optional, but recommended) - mail body (if null, assume $subject_or_data is the entire mail body with headers etc) * @return bool - true on success, otherwise false - * I did something that is working with 465 and 587. The previous one doesnt work at all - * Sorry fot that. Had to do a litle tweak do work with broadcast-message.php - * Sorry for the bad english :D */ -function smtp_mail($to, $from, $subject_or_data, $body = null) +function smtp_mail(string $to, string $from, string $subject_or_data, ?string $body = null): bool { global $CONF; - $server = $CONF['smtp_server']; - $port = (int)$CONF['smtp_port']; + $server = $CONF['smtp_server']; + $port = (int)$CONF['smtp_port']; $timeout = 30; $helo = !empty($CONF['smtp_client']) @@ -1329,7 +1325,7 @@ function smtp_mail($to, $from, $subject_or_data, $body = null) $username = $CONF['smtp_username'] ?? ''; $password = $CONF['admin_smtp_password'] ?? ''; - $type = $CONF['smtp_type'] ?? 'starttls'; + $type = $CONF['smtp_type'] ?? 'starttls'; // Building of SMTP payload if ($body === null) { @@ -1403,6 +1399,7 @@ function smtp_mail($to, $from, $subject_or_data, $body = null) return true; } + //end // auxiliary function function smtp_expect($socket, $code) @@ -1421,6 +1418,7 @@ function smtp_expect($socket, $code) } return true; } + //end commit /** * smtp_get_admin_email diff --git a/model/MailboxHandler.php b/model/MailboxHandler.php index 63cdc802..9eff6280 100644 --- a/model/MailboxHandler.php +++ b/model/MailboxHandler.php @@ -510,7 +510,7 @@ class MailboxHandler extends PFAHandler $fSubject = Config::lang('pSendmail_subject_text'); $fBody = Config::read('welcome_text'); - if (!smtp_mail($fTo, $fFrom, $fSubject, smtp_get_admin_password(), $fBody)) { + if (!smtp_mail($fTo, $fFrom, $fSubject, $fBody)) { $this->errormsg[] = Config::lang_f('pSendmail_result_error', $this->id); return false; } diff --git a/public/sendmail.php b/public/sendmail.php index 8922fb4a..3c6ec78b 100644 --- a/public/sendmail.php +++ b/public/sendmail.php @@ -64,7 +64,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { } if ($error != 1) { - if (!smtp_mail($fTo, $fFrom, $fSubject, smtp_get_admin_password(), $tBody)) { + if (!smtp_mail($fTo, $fFrom, $fSubject, $tBody)) { flash_error(Config::lang_f('pSendmail_result_error', $fTo)); } else { flash_info(Config::lang_f('pSendmail_result_success', $fTo)); diff --git a/public/users/password-recover.php b/public/users/password-recover.php index 991b9304..6e589b16 100644 --- a/public/users/password-recover.php +++ b/public/users/password-recover.php @@ -48,10 +48,10 @@ function sendCodebyEmail($to, $username, $code) { $url = getSiteUrl($_SERVER) . 'password-change.php?username=' . urlencode($username) . '&code=' . $code; - return smtp_mail($to, + return smtp_mail( + $to, smtp_get_admin_email(false), Config::Lang('pPassword_welcome'), - Config::read('admin_smtp_password'), Config::lang_f('pPassword_recovery_email_body', $url)); } @@ -108,7 +108,7 @@ if ($_SERVER['REQUEST_METHOD'] === "POST") { // throttle password reset requests to prevent brute force attack $elapsed_time = microtime(true) - $start_time; if ($elapsed_time < 2 * pow(10, 6)) { - usleep((int) (2 * pow(10, 6) - $elapsed_time)); + usleep((int)(2 * pow(10, 6) - $elapsed_time)); } flash_info(Config::Lang('pPassword_recovery_processed'));