From b8957a8a24ff7c7bfb8659a4e9740aef855804cc Mon Sep 17 00:00:00 2001
From: solocla
Date: Fri, 4 Sep 2026 10:03:38 +0200
Subject: [PATCH] fixed mailer class
---
public/acceptbookingclass.php | 42 +++----
public/bookandgo.php | 69 ++++++-----
public/cancella-prenotazione.php | 41 +++----
public/class/mailer.php | 6 -
public/delete_lesson.php | 9 +-
public/emailsend.php | 65 ++++------
public/mail/emailtemplate2.php | 92 +++-----------
public/notificationmail.php | 157 +++++++++++-------------
public/orderpropagate.php | 201 ++++++++++++++-----------------
public/promemoria-cron.php | 39 +++---
public/propagatesingleorder.php | 40 +++---
public/rebookandgo.php | 194 +++++++++++++++--------------
public/rejectbookingclass.php | 123 +++++++++----------
public/send_email.php | 30 ++---
public/userpanel.php | 2 +-
15 files changed, 479 insertions(+), 631 deletions(-)
diff --git a/public/acceptbookingclass.php b/public/acceptbookingclass.php
index 35e4ea9..489652a 100644
--- a/public/acceptbookingclass.php
+++ b/public/acceptbookingclass.php
@@ -1,17 +1,18 @@
- Ciao $firstname ,
@@ -65,20 +64,21 @@ if (isset($_GET['idbookingclass'])) {
$mail = new PHPMailer(true);
- $mail->isSMTP(); // Set mailer to use SMTP
- $mail->Host = 'mail.yogasoul.it'; // Specify main and backup server
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = 'info@yogasoul.it'; // SMTP username
- $mail->Password = '!Testolina88'; // SMTP password
- $mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
- $mail->Port = '587';
+ $mail->isSMTP();
+ $mail->Host = $_ENV['MAIL_HOST'];
+ $mail->SMTPAuth = true;
+ $mail->Username = $_ENV['MAIL_USERNAME'];
+ $mail->Password = $_ENV['MAIL_PASSWORD'];
+ $mail->SMTPSecure = $_ENV['MAIL_ENCRYPTION']; // ssl
+ $mail->Port = (int) $_ENV['MAIL_PORT']; // 465
+ $mail->CharSet = 'UTF-8';
include('mail/emailtemplate2.php');
// Email body content
$htmlContent = $mailmessage1;
- $mail->From = 'info@yogasoul.it';
- $mail->FromName = 'YogiBook [YogaSoul]';
+ $mail->From = $_ENV['MAIL_FROM_ADDRESS'];
+ $mail->FromName = $_ENV['MAIL_FROM_NAME'];
$mail->addAddress($emailuser); // Add a recipient
$mail->Subject = "YogiBook - Lezione riprogrammata con successo!";
@@ -104,7 +104,3 @@ if (isset($_GET['idbookingclass'])) {
} else {
echo "Parametro 'idbookingclass' non trovato nella richiesta GET.";
}
-
-// Chiudi la connessione al database
-$conn->close();
-?>
\ No newline at end of file
diff --git a/public/bookandgo.php b/public/bookandgo.php
index 06a1cb3..6ef04b6 100644
--- a/public/bookandgo.php
+++ b/public/bookandgo.php
@@ -1,33 +1,23 @@
connect_error) {
- die("Connessione al database fallita: " . $conn->connect_error);
-}
+// Riusa la connessione già aperta da bkngstm.php
+$conn = $bkngstm;
// Recupera dateschedule e servicename
$query = "SELECT serviceschedule.dateschedule, service.servicename
@@ -45,7 +35,6 @@ if ($resultnew->num_rows > 0) {
$servicename = $rownew['servicename'] ?? 'N/D';
} else {
$stmt->close();
- $conn->close();
die("Errore: Nessun orario trovato per idserviceschedule = $idnewbooking.");
}
$stmt->close();
@@ -53,6 +42,19 @@ $stmt->close();
// Formatta la data per l'email
$newtimeformat = date("d-m-Y H:i", strtotime($newtime));
+// Recupera nome ed email dell'utente per la mail
+$firstname = '';
+$emailuser = '';
+$stmtUser = $conn->prepare("SELECT first_name, email FROM auth_users WHERE id = ?");
+$stmtUser->bind_param("i", $iduser);
+$stmtUser->execute();
+$resUser = $stmtUser->get_result();
+if ($rowUser = $resUser->fetch_assoc()) {
+ $firstname = $rowUser['first_name'] ?? '';
+ $emailuser = $rowUser['email'] ?? '';
+}
+$stmtUser->close();
+
// Inserisce la nuova prenotazione in bookingclass
$insertQuery = "INSERT INTO bookingclass (idserviceschedule, iduser, prevbookingstart, idprevserviceschedule, idservice, idorder, bookingstart, status)
VALUES (?, ?, '0', '0', ?, ?, ?, 'pending')";
@@ -60,7 +62,6 @@ $stmt = $conn->prepare($insertQuery);
$stmt->bind_param("iiiis", $idnewbooking, $iduser, $idservicenew, $idorder, $newtime);
if (!$stmt->execute()) {
$stmt->close();
- $conn->close();
die("Errore durante l'inserimento della nuova prenotazione: " . $conn->error);
}
$stmt->close();
@@ -75,8 +76,13 @@ $stmt->bind_param("ii", $iduser, $idorder);
$stmt->execute();
$stmt->close();
-// Chiudi la connessione al database
-$conn->close();
+// Connessione $bkngstm gestita globalmente: non la chiudiamo qui
+
+// Se non abbiamo un'email valida, salta l'invio ma completa comunque il flusso
+if ($emailuser === '') {
+ header("Location: userpanel.php?reprogram=Y");
+ exit();
+}
// Configura il contenuto dell'email
$messageedit = "
@@ -141,23 +147,24 @@ include('mail/emailtemplate2.php');
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
- $mail->Host = 'mail.yogasoul.it';
- $mail->SMTPAuth = true;
- $mail->Username = 'info@yogasoul.it';
- $mail->Password = '!Testolina88';
- $mail->SMTPSecure = 'tls';
- $mail->Port = 587;
+ $mail->Host = $_ENV['MAIL_HOST'];
+ $mail->SMTPAuth = true;
+ $mail->Username = $_ENV['MAIL_USERNAME'];
+ $mail->Password = $_ENV['MAIL_PASSWORD'];
+ $mail->SMTPSecure = $_ENV['MAIL_ENCRYPTION'];
+ $mail->Port = (int) $_ENV['MAIL_PORT'];
- $mail->setFrom('info@yogasoul.it', 'YogiBook [YogaSoul]');
+ $mail->setFrom($_ENV['MAIL_FROM_ADDRESS'], $_ENV['MAIL_FROM_NAME']);
$mail->addAddress($emailuser);
$mail->Subject = "Proposta di riprogrammazione!";
- $mail->Body = $mailmessage1;
+ $mail->Body = $mailmessage1;
$mail->AltBody = 'Hai inviato una richiesta di riprogrammazione della tua lezione per il servizio ' . $servicename . ' il ' . $newtimeformat . '. La tua richiesta è in fase di accettazione.';
$mail->send();
} catch (Exception $e) {
- die("Errore durante l'invio dell'email: " . $mail->ErrorInfo);
+ // La prenotazione è già salvata: logghiamo l'errore mail ma non blocchiamo l'utente
+ error_log("Errore invio mail riprogrammazione (iduser $iduser): " . $mail->ErrorInfo);
}
// Esegui il reindirizzamento
diff --git a/public/cancella-prenotazione.php b/public/cancella-prenotazione.php
index 390e563..9261c96 100644
--- a/public/cancella-prenotazione.php
+++ b/public/cancella-prenotazione.php
@@ -1,20 +1,13 @@
connect_error) {
- die("Connessione al database fallita: " . $conn->connect_error);
-}
-
+// Riusa la connessione già aperta da bkngstm.php
+$conn = $bkngstm;
// Inizializza log
$logFile = 'cancella_prenotazione_log.txt';
$logMessage = "Esecuzione cancellazione: " . date('Y-m-d H:i:s') . "\n";
@@ -47,7 +40,7 @@ if (!$idbookingclass) {
// Verifica validità: token corrisponde, lezione futura
$query = "SELECT bc.*, ob.expireon, au.email, au.first_name, s.servicename
FROM bookingclass bc
- LEFT JOIN orderbook ob ON bc.idorder = ob.order_id
+ LEFT JOIN orderbook ob ON bc.idorder = ob.idorderbook
LEFT JOIN auth_users au ON bc.iduser = au.id
LEFT JOIN service s ON bc.idservice = s.idservice
WHERE bc.idbookingclass = ?
@@ -176,19 +169,15 @@ if (isset($_GET['action']) && $_GET['action'] === 'cancel') {
YogiBook - YogaSoul
";
- require_once 'phpmailer/src/Exception.php';
- require_once 'phpmailer/src/PHPMailer.php';
- require_once 'phpmailer/src/SMTP.php';
-
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
- $mail->Host = 'mail.yogasoul.it';
- $mail->SMTPAuth = true;
- $mail->Username = 'info@yogasoul.it';
- $mail->Password = '!Testolina88';
- $mail->SMTPSecure = 'tls';
- $mail->Port = 587;
+ $mail->Host = $_ENV['MAIL_HOST'];
+ $mail->SMTPAuth = true;
+ $mail->Username = $_ENV['MAIL_USERNAME'];
+ $mail->Password = $_ENV['MAIL_PASSWORD'];
+ $mail->SMTPSecure = $_ENV['MAIL_ENCRYPTION'];
+ $mail->Port = (int) $_ENV['MAIL_PORT'];
if (!file_exists('mail/emailtemplate2.php')) {
throw new Exception("File emailtemplate2.php non trovato.");
@@ -201,8 +190,8 @@ if (isset($_GET['action']) && $_GET['action'] === 'cancel') {
$htmlContent = str_replace('{message}', $messagecancel, $mailmessage1);
- $mail->From = 'info@yogasoul.it';
- $mail->FromName = 'YogiBook [YogaSoul]';
+ $mail->From = $_ENV['MAIL_FROM_ADDRESS'];
+ $mail->FromName = $_ENV['MAIL_FROM_NAME'];
$mail->addAddress($emailuser);
$mail->Subject = "YogiBook - Lezione cancellata con successo!";
$mail->Body = $htmlContent;
@@ -314,5 +303,5 @@ file_put_contents($logFile, $logMessage, FILE_APPEND);