fix send mail with python script

This commit is contained in:
Francesco Picone
2025-12-09 17:35:40 +01:00
parent b79b31df69
commit 568a02251c
5 changed files with 296 additions and 13 deletions

View File

@@ -49,13 +49,10 @@ Piattaforma completa per vendere videolezioni e lezioni live di Pilates. Svilupp
### Requisiti
- **PHP** 7.4 o superiore (8.0+ raccomandato)
- **MySQL** 5.7 o superiore (o MariaDB 10.3+)
- **Python** 3.6 o superiore (per invio email SMTP)
- **Web Server** (Apache, Nginx, o PHP built-in server per sviluppo)
- **Account PayPal** Sandbox (per test) o Business (per produzione)
- **FFmpeg** (opzionale, per conversione automatica video in MP4)
- **PHP** 7.4 o superiore
- **MySQL** 5.7 o superiore (o MariaDB 10.3+)
- **Web Server** (Apache, Nginx, o PHP built-in server per sviluppo)
- **Account PayPal** Sandbox (per test) o Business (per produzione)
### Passo 1: Copia i File
```bash
@@ -115,7 +112,7 @@ 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:
Per inviare email (recupero password, registrazione), configura Gmail SMTP:
1. **Abilita verifica 2 fattori** sul tuo account Gmail
2. Vai su [Password per le app](https://myaccount.google.com/apppasswords)
@@ -127,14 +124,30 @@ In `includes/config.php`:
```php
define('USE_SMTP', true); // Attiva SMTP
define('SMTP_HOST', 'smtp.gmail.com');
define('SMTP_PORT', 587);
define('SMTP_PORT', 587); // 587 per TLS, 465 per SSL
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');
define('SMTP_ENCRYPTION', 'tls'); // tls (porta 587) o ssl (porta 465)
```
⚠️ **Non usare la password normale di Gmail**, usa solo la password applicazione!
**Sistema di invio email:**
- Le email vengono inviate tramite script Python (`send_email.py`)
- Python 3.6+ deve essere installato sul server
- Lo script legge automaticamente le credenziali da `config.php`
- Più affidabile e stabile rispetto a SMTP nativo PHP
Verifica installazione Python:
```bash
python3 --version
```
Se Python non è installato:
- **Ubuntu/Debian**: `sudo apt install python3`
- **CentOS/RHEL**: `sudo yum install python3`
- **Windows**: Scarica da [python.org](https://www.python.org/downloads/)
#### PayPal Sandbox (per Test)
1. Vai su [PayPal Developer](https://developer.paypal.com/)
2. Accedi con il tuo account PayPal
@@ -520,11 +533,39 @@ Crea `.htaccess` nella cartella `includes/`:
- La piattaforma è già aggiornata per gestire valori null
- Se vedi ancora warning, verifica che tutti i file siano aggiornati
### Reset Password non funziona
- Verifica che le email vengano inviate correttamente
- Configura SMTP in `config.php` se `mail()` non funziona
- Il token scade dopo 1 ora per sicurezza
- Controlla che la tabella `users` abbia i campi `reset_token` e `reset_expires`
### Reset Password / Email non funzionano
- Verifica che Python 3 sia installato: `python3 --version`
- Controlla credenziali SMTP in `config.php`
- Verifica che `send_email.py` abbia permessi esecuzione
- Testa invio dal profilo admin: pulsante "🧪 Testa Invio Email"
- Il token reset scade dopo 1 ora per sicurezza
- Controlla log errori PHP per dettagli (`error_log()`)
**Test manuale script Python:**
```bash
cd /path/to/pilates-platform
python3 send_email.py '{"to":"test@esempio.com","subject":"Test","html":"<p>Test email</p>"}'
```
**Errori comuni:**
- `python3: command not found` → Installa Python 3
- `Authentication failed` → Verifica password applicazione Gmail
- `Connection refused` → Controlla porta (587 per TLS, 465 per SSL)
- `Script not found` → Verifica che `send_email.py` esista nella root del progetto
- `Permission denied` → Su Linux: `chmod +x send_email.py`
- Il token reset scade dopo 1 ora per sicurezza
- Controlla log errori PHP per dettagli
**Test manuale script Python:**
```bash
cd /path/to/pilates-platform
python3 send_email.py '{"to":"test@esempio.com","subject":"Test","html":"<p>Test email</p>"}'
```
**Errori comuni:**
- `python3: command not found` → Installa Python 3
- `Authentication failed` → Verifica password applicazione Gmail
- `Connection refused` → Controlla porta (587 per TLS, 465 per SSL)
---
@@ -550,6 +591,7 @@ pilates-platform/
├── process_payment.php # Elabora pagamento PayPal
├── stream_video.php # Streaming protetto video (verifica permessi)
├── convert_videos.php # Conversione batch video in MP4 H.264
├── send_email.py # Script Python per invio email SMTP
├── test_password.php # Utility test hash password (debug)
├── test_email.php # Utility test invio email SMTP (debug)
└── README.md # Questo file