From b79b31df69b20dfca3bd961a7fd0724c273d9b40 Mon Sep 17 00:00:00 2001 From: Francesco Picone Date: Tue, 9 Dec 2025 17:27:26 +0100 Subject: [PATCH] fix --- includes/config.php | 4 ++-- includes/functions.php | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/includes/config.php b/includes/config.php index 0e9c983..b070f5b 100644 --- a/includes/config.php +++ b/includes/config.php @@ -76,10 +76,10 @@ define('USE_SMTP', true); // Imposta false per usare mail() PHP di base // Impostazioni SMTP - Gmail // Per Gmail: usa password applicazione da https://myaccount.google.com/apppasswords define('SMTP_HOST', 'smtp.gmail.com'); -define('SMTP_PORT', 465); +define('SMTP_PORT', 587); define('SMTP_USERNAME', 'pyco.networking@gmail.com'); // Inserisci la tua email Gmail define('SMTP_PASSWORD', 'iaxuxsvggkfmbzpa'); // Password applicazione (16 caratteri) -define('SMTP_ENCRYPTION', 'ssl'); // tls o ssl +define('SMTP_ENCRYPTION', 'tls'); // tls (porta 587) o ssl (porta 465) // ============================================ // CONFIGURAZIONE UPLOAD FILE diff --git a/includes/functions.php b/includes/functions.php index 9bd63c8..ac30bdb 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -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; }