fix mail
This commit is contained in:
51
README.md
51
README.md
@@ -101,6 +101,27 @@ define('ADMIN_EMAIL', 'tua-email@esempio.com'); // Tua email
|
|||||||
define('SECRET_KEY', 'CAMBIA-QUESTA-CHIAVE-CON-STRINGA-CASUALE-LUNGA-E-SICURA');
|
define('SECRET_KEY', 'CAMBIA-QUESTA-CHIAVE-CON-STRINGA-CASUALE-LUNGA-E-SICURA');
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Email SMTP con Gmail ⭐ **IMPORTANTE**
|
||||||
|
Per inviare email (recupero password), configura Gmail SMTP:
|
||||||
|
|
||||||
|
1. **Abilita verifica 2 fattori** sul tuo account Gmail
|
||||||
|
2. Vai su [Password per le app](https://myaccount.google.com/apppasswords)
|
||||||
|
3. Seleziona "App: Posta" e "Dispositivo: Altro (nome personalizzato)"
|
||||||
|
4. Inserisci "Pilates Platform" e clicca **Genera**
|
||||||
|
5. Copia la password di 16 caratteri generata
|
||||||
|
|
||||||
|
In `includes/config.php`:
|
||||||
|
```php
|
||||||
|
define('USE_SMTP', true); // Attiva SMTP
|
||||||
|
define('SMTP_HOST', 'smtp.gmail.com');
|
||||||
|
define('SMTP_PORT', 587);
|
||||||
|
define('SMTP_USERNAME', 'tua-email@gmail.com'); // La tua Gmail
|
||||||
|
define('SMTP_PASSWORD', 'abcd efgh ijkl mnop'); // Password app (16 caratteri)
|
||||||
|
define('SMTP_ENCRYPTION', 'tls');
|
||||||
|
```
|
||||||
|
|
||||||
|
⚠️ **Non usare la password normale di Gmail**, usa solo la password applicazione!
|
||||||
|
|
||||||
#### PayPal Sandbox (per Test)
|
#### PayPal Sandbox (per Test)
|
||||||
1. Vai su [PayPal Developer](https://developer.paypal.com/)
|
1. Vai su [PayPal Developer](https://developer.paypal.com/)
|
||||||
2. Accedi con il tuo account PayPal
|
2. Accedi con il tuo account PayPal
|
||||||
@@ -263,14 +284,17 @@ Apri `assets/css/style.css` e modifica le variabili CSS:
|
|||||||
- Dimensioni: 1920x600px
|
- Dimensioni: 1920x600px
|
||||||
- Immagine di sfondo homepage
|
- Immagine di sfondo homepage
|
||||||
|
|
||||||
### Email
|
### Email con Gmail SMTP
|
||||||
Per usare SMTP invece di `mail()` PHP, decomenta in `includes/config.php`:
|
La piattaforma usa Gmail SMTP per inviare email in modo affidabile:
|
||||||
|
|
||||||
|
1. **Configurato di default** in `includes/config.php`
|
||||||
|
2. Inserisci le tue credenziali Gmail
|
||||||
|
3. Usa **Password per le app** (non la password Gmail normale)
|
||||||
|
4. Testa inviando una richiesta di reset password
|
||||||
|
|
||||||
|
**Per disattivare SMTP** e usare `mail()` PHP:
|
||||||
```php
|
```php
|
||||||
define('SMTP_HOST', 'smtp.gmail.com');
|
define('USE_SMTP', false); // In config.php
|
||||||
define('SMTP_PORT', 587);
|
|
||||||
define('SMTP_USERNAME', 'tua-email@gmail.com');
|
|
||||||
define('SMTP_PASSWORD', 'tua-app-password');
|
|
||||||
define('SMTP_ENCRYPTION', 'tls');
|
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -378,9 +402,12 @@ Crea `.htaccess` nella cartella `includes/`:
|
|||||||
- MySQL non accetta trattini nei nomi database, usa underscore
|
- MySQL non accetta trattini nei nomi database, usa underscore
|
||||||
|
|
||||||
### Le email non vengono inviate
|
### Le email non vengono inviate
|
||||||
- Configura SMTP in `config.php`
|
- Verifica credenziali Gmail in `config.php` (SMTP_USERNAME e SMTP_PASSWORD)
|
||||||
- Verifica che `mail()` PHP funzioni sul tuo server
|
- Usa **Password per le app** Gmail (non la password normale)
|
||||||
- Controlla la cartella spam
|
- Verifica che `USE_SMTP` sia `true`
|
||||||
|
- Controlla la cartella spam del destinatario
|
||||||
|
- Verifica log errori PHP per messaggi "SMTP Error"
|
||||||
|
- Assicurati che il server permetta connessioni SMTP in uscita (porta 587)
|
||||||
|
|
||||||
### I video non si vedono
|
### I video non si vedono
|
||||||
- Verifica che l'URL sia corretto
|
- Verifica che l'URL sia corretto
|
||||||
@@ -539,7 +566,9 @@ Questo progetto è stato creato come piattaforma custom. Sei libero di modificar
|
|||||||
|
|
||||||
Dopo l'installazione:
|
Dopo l'installazione:
|
||||||
- [ ] Cambia password admin (profilo o reset_admin_password.sql)
|
- [ ] Cambia password admin (profilo o reset_admin_password.sql)
|
||||||
- [ ] Configura SMTP per invio email
|
- [ ] **Configura Gmail SMTP** (obbligatorio per recupero password)
|
||||||
|
- [ ] Genera password applicazione Gmail
|
||||||
|
- [ ] Inserisci credenziali SMTP in config.php
|
||||||
- [ ] Testa recupero password
|
- [ ] Testa recupero password
|
||||||
- [ ] Configura PayPal Sandbox
|
- [ ] Configura PayPal Sandbox
|
||||||
- [ ] Carica almeno 3 lezioni demo
|
- [ ] Carica almeno 3 lezioni demo
|
||||||
|
|||||||
@@ -62,18 +62,20 @@ define('PAYPAL_API_URL', PAYPAL_SANDBOX ?
|
|||||||
// CONFIGURAZIONE EMAIL
|
// CONFIGURAZIONE EMAIL
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
// Configurazione per l'invio di email (usa SMTP per produzione)
|
// Configurazione per l'invio di email
|
||||||
define('MAIL_FROM', 'noreply@pilatesstudio.com');
|
define('MAIL_FROM', 'noreply@pilatesstudio.com');
|
||||||
define('MAIL_FROM_NAME', 'Pilates Studio');
|
define('MAIL_FROM_NAME', 'Pilates Studio');
|
||||||
|
|
||||||
// Impostazioni SMTP (opzionali - commentate se usi mail() PHP di base)
|
// Usa SMTP per invio email affidabile
|
||||||
/*
|
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_HOST', 'smtp.gmail.com');
|
||||||
define('SMTP_PORT', 587);
|
define('SMTP_PORT', 587);
|
||||||
define('SMTP_USERNAME', 'tua-email@gmail.com');
|
define('SMTP_USERNAME', 'tua-email@gmail.com'); // Inserisci la tua email Gmail
|
||||||
define('SMTP_PASSWORD', 'tua-password-applicazione');
|
define('SMTP_PASSWORD', 'tua-password-applicazione'); // Password applicazione (16 caratteri)
|
||||||
define('SMTP_ENCRYPTION', 'tls');
|
define('SMTP_ENCRYPTION', 'tls'); // tls o ssl
|
||||||
*/
|
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// CONFIGURAZIONE UPLOAD FILE
|
// CONFIGURAZIONE UPLOAD FILE
|
||||||
|
|||||||
@@ -412,11 +412,115 @@ function mark_token_as_used($token) {
|
|||||||
* @return bool True se inviata, false altrimenti
|
* @return bool True se inviata, false altrimenti
|
||||||
*/
|
*/
|
||||||
function send_email($to, $subject, $message) {
|
function send_email($to, $subject, $message) {
|
||||||
|
if (USE_SMTP) {
|
||||||
|
return send_smtp_email($to, $subject, $message);
|
||||||
|
} else {
|
||||||
|
// Fallback a mail() PHP nativo
|
||||||
$headers = "MIME-Version: 1.0" . "\r\n";
|
$headers = "MIME-Version: 1.0" . "\r\n";
|
||||||
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
|
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
|
||||||
$headers .= "From: " . MAIL_FROM_NAME . " <" . MAIL_FROM . ">" . "\r\n";
|
$headers .= "From: " . MAIL_FROM_NAME . " <" . MAIL_FROM . ">" . "\r\n";
|
||||||
|
|
||||||
return mail($to, $subject, $message, $headers);
|
return mail($to, $subject, $message, $headers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invia email tramite SMTP (Gmail)
|
||||||
|
*
|
||||||
|
* @param string $to Email destinatario
|
||||||
|
* @param string $subject Oggetto email
|
||||||
|
* @param string $message Corpo email (HTML)
|
||||||
|
* @return bool True se inviata, false altrimenti
|
||||||
|
*/
|
||||||
|
function send_smtp_email($to, $subject, $message) {
|
||||||
|
try {
|
||||||
|
// Connessione al server SMTP
|
||||||
|
$smtp = fsockopen(SMTP_HOST, SMTP_PORT, $errno, $errstr, 30);
|
||||||
|
|
||||||
|
if (!$smtp) {
|
||||||
|
error_log("SMTP Error: Impossibile connettersi a " . SMTP_HOST . ":" . SMTP_PORT);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Funzione helper per leggere risposta
|
||||||
|
$read = function() use ($smtp) {
|
||||||
|
return fgets($smtp, 515);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Funzione helper per inviare comando
|
||||||
|
$send = function($cmd) use ($smtp) {
|
||||||
|
fputs($smtp, $cmd . "\r\n");
|
||||||
|
};
|
||||||
|
|
||||||
|
// Leggi il banner di benvenuto
|
||||||
|
$read();
|
||||||
|
|
||||||
|
// Inizia handshake SMTP
|
||||||
|
$send("EHLO " . SMTP_HOST);
|
||||||
|
$read();
|
||||||
|
|
||||||
|
// Inizia TLS se richiesto
|
||||||
|
if (SMTP_ENCRYPTION === 'tls') {
|
||||||
|
$send("STARTTLS");
|
||||||
|
$read();
|
||||||
|
stream_socket_enable_crypto($smtp, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
|
||||||
|
|
||||||
|
$send("EHLO " . SMTP_HOST);
|
||||||
|
$read();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Autenticazione
|
||||||
|
$send("AUTH LOGIN");
|
||||||
|
$read();
|
||||||
|
|
||||||
|
$send(base64_encode(SMTP_USERNAME));
|
||||||
|
$read();
|
||||||
|
|
||||||
|
$send(base64_encode(SMTP_PASSWORD));
|
||||||
|
$response = $read();
|
||||||
|
|
||||||
|
// Verifica autenticazione
|
||||||
|
if (strpos($response, '235') === false) {
|
||||||
|
error_log("SMTP Error: Autenticazione fallita - " . $response);
|
||||||
|
fclose($smtp);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Imposta mittente
|
||||||
|
$send("MAIL FROM: <" . MAIL_FROM . ">");
|
||||||
|
$read();
|
||||||
|
|
||||||
|
// Imposta destinatario
|
||||||
|
$send("RCPT TO: <" . $to . ">");
|
||||||
|
$read();
|
||||||
|
|
||||||
|
// Inizia corpo messaggio
|
||||||
|
$send("DATA");
|
||||||
|
$read();
|
||||||
|
|
||||||
|
// Costruisci headers
|
||||||
|
$headers = "From: " . MAIL_FROM_NAME . " <" . MAIL_FROM . ">\r\n";
|
||||||
|
$headers .= "To: <" . $to . ">\r\n";
|
||||||
|
$headers .= "Subject: " . $subject . "\r\n";
|
||||||
|
$headers .= "MIME-Version: 1.0\r\n";
|
||||||
|
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
|
||||||
|
$headers .= "Date: " . date('r') . "\r\n";
|
||||||
|
|
||||||
|
// Invia email
|
||||||
|
$send($headers . "\r\n" . $message . "\r\n.");
|
||||||
|
$read();
|
||||||
|
|
||||||
|
// Chiudi connessione
|
||||||
|
$send("QUIT");
|
||||||
|
$read();
|
||||||
|
fclose($smtp);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log("SMTP Error: " . $e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user