This commit is contained in:
Francesco Picone
2025-12-09 17:27:26 +01:00
parent b612146dfe
commit b79b31df69
2 changed files with 22 additions and 5 deletions

View File

@@ -442,11 +442,28 @@ function send_email($to, $subject, $message) {
*/
function send_smtp_email($to, $subject, $message) {
try {
// Connessione al server SMTP
$smtp = fsockopen(SMTP_HOST, SMTP_PORT, $errno, $errstr, 30);
// Connessione al server SMTP con supporto SSL/TLS
$context = stream_context_create([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
]);
// Per SSL (porta 465) usa protocollo ssl://, per TLS (porta 587) connessione normale
$protocol = (SMTP_ENCRYPTION === 'ssl') ? 'ssl://' : '';
$smtp = stream_socket_client(
$protocol . SMTP_HOST . ':' . SMTP_PORT,
$errno,
$errstr,
30,
STREAM_CLIENT_CONNECT,
$context
);
if (!$smtp) {
error_log("SMTP Error: Impossibile connettersi a " . SMTP_HOST . ":" . SMTP_PORT);
error_log("SMTP Error: Impossibile connettersi a " . SMTP_HOST . ":" . SMTP_PORT . " - $errstr ($errno)");
return false;
}