fixed mailer class
This commit is contained in:
+106
-88
@@ -1,65 +1,96 @@
|
||||
<?php
|
||||
require_once('include/headscript.php');
|
||||
require_once __DIR__ . '/class/mailer.php';
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
?>
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
|
||||
require_once('include/headscript.php');
|
||||
if (isset($_GET['idpreviousbooking'])) { $idpreviousbooking = $_GET['idpreviousbooking']; }
|
||||
if (isset($_GET['idnewbooking'])) { $idnewbooking = $_GET['idnewbooking']; }
|
||||
if (isset($_GET['iduser'])) { $iduser = $_GET['iduser']; }
|
||||
if (isset($_GET['idservicenew'])) { $idservicenew = $_GET['idservicenew']; }
|
||||
|
||||
// Effettua la cancellazione del record nella tabella bookingclass
|
||||
// Sostituisci questi passaggi con il codice reale per connettersi al database e eseguire la query di cancellazione
|
||||
$idpreviousbooking = isset($_GET['idpreviousbooking']) ? (int) $_GET['idpreviousbooking'] : 0;
|
||||
$idnewbooking = isset($_GET['idnewbooking']) ? (int) $_GET['idnewbooking'] : 0;
|
||||
$iduser = isset($_GET['iduser']) ? (int) $_GET['iduser'] : 0;
|
||||
$idservicenew = isset($_GET['idservicenew']) ? (int) $_GET['idservicenew'] : 0;
|
||||
|
||||
// Recupera i valori di bookingstart e idserviceschedule dalla tabella bookingclass
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
$selectQuery = "SELECT bookingstart, idserviceschedule, idorder FROM bookingclass WHERE idbookingclass = $idpreviousbooking";
|
||||
$result = $conn->query($selectQuery);
|
||||
|
||||
$sqlnewbook = "SELECT dateschedule FROM serviceschedule WHERE idserviceschedule = $idnewbooking";
|
||||
$resultnew = $conn->query($sqlnewbook);
|
||||
if ($idpreviousbooking === 0 || $idnewbooking === 0 || $iduser === 0 || $idservicenew === 0) {
|
||||
die("Errore: Parametri mancanti.");
|
||||
}
|
||||
|
||||
// Estrai il risultato e memorizzalo in $newtime
|
||||
$rownew = $resultnew->fetch_assoc();
|
||||
$newtime = $rownew["dateschedule"];
|
||||
// Riusa la connessione già aperta da bkngstm.php
|
||||
$conn = $bkngstm;
|
||||
|
||||
if ($result && $result->num_rows > 0) {
|
||||
$row = $result->fetch_assoc();
|
||||
$prevBookingStart = $row['bookingstart'];
|
||||
$idPrevServiceSchedule = $row['idserviceschedule'];
|
||||
$globalidorder = $row['idorder'];
|
||||
// Nuovo orario della lezione scelta
|
||||
$stmt = $conn->prepare("SELECT dateschedule FROM serviceschedule WHERE idserviceschedule = ?");
|
||||
$stmt->bind_param("i", $idnewbooking);
|
||||
$stmt->execute();
|
||||
$resultnew = $stmt->get_result();
|
||||
$rownew = $resultnew->fetch_assoc();
|
||||
$newtime = $rownew['dateschedule'] ?? null;
|
||||
$stmt->close();
|
||||
|
||||
// Effettua la cancellazione del record nella tabella bookingclass
|
||||
$deleteQuery = "DELETE FROM bookingclass WHERE idbookingclass = $idpreviousbooking";
|
||||
$conn->query($deleteQuery);
|
||||
if (!$newtime) {
|
||||
die("Errore: orario della nuova lezione non trovato.");
|
||||
}
|
||||
|
||||
// Effettua l'inserimento del nuovo record nella tabella bookingclass
|
||||
$insertQuery = "INSERT INTO bookingclass (idserviceschedule, iduser, prevbookingstart, idprevserviceschedule, idservice, idorder, bookingstart, status)
|
||||
VALUES ($idnewbooking, $iduser, '$prevBookingStart', $idPrevServiceSchedule, $idservicenew, $globalidorder, '$newtime', 'pending')";
|
||||
$conn->query($insertQuery);
|
||||
// Dati della prenotazione precedente
|
||||
$stmt = $conn->prepare("SELECT bookingstart, idserviceschedule, idorder FROM bookingclass WHERE idbookingclass = ?");
|
||||
$stmt->bind_param("i", $idpreviousbooking);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
// Aggiorna la tabella orderbook
|
||||
echo $globalidorder;
|
||||
echo 'ciao';
|
||||
if ($result->num_rows === 0) {
|
||||
$stmt->close();
|
||||
die("Errore: prenotazione precedente non trovata.");
|
||||
}
|
||||
|
||||
$updateQuery = "UPDATE orderbook SET reprogrammed = reprogrammed + 1 WHERE idorderbook = $globalidorder";
|
||||
$conn->query($updateQuery);
|
||||
echo "Query di aggiornamento: " . $updateQuery;
|
||||
// Chiudi la connessione al database
|
||||
$conn->close();
|
||||
|
||||
|
||||
$newtimeformat = date("d-m-Y H:i", strtotime($newtime));
|
||||
require 'phpmailer/src/Exception.php';
|
||||
require 'phpmailer/src/PHPMailer.php';
|
||||
require 'phpmailer/src/SMTP.php';
|
||||
//mail to client
|
||||
$messageedit=" <p style='font-size: 14px; line-height: 190%;'><span style='font-size: 18px; line-height: 34.2px;'><strong><span style='line-height: 34.2px; font-size: 18px;'> Ciao $firstname , </span></strong></span></p>
|
||||
$row = $result->fetch_assoc();
|
||||
$prevBookingStart = $row['bookingstart'];
|
||||
$idPrevServiceSchedule = (int) $row['idserviceschedule'];
|
||||
$globalidorder = (int) $row['idorder'];
|
||||
$stmt->close();
|
||||
|
||||
// Cancella la prenotazione precedente
|
||||
$stmt = $conn->prepare("DELETE FROM bookingclass WHERE idbookingclass = ?");
|
||||
$stmt->bind_param("i", $idpreviousbooking);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
|
||||
// Inserisci la nuova prenotazione (pending)
|
||||
$stmt = $conn->prepare(
|
||||
"INSERT INTO bookingclass (idserviceschedule, iduser, prevbookingstart, idprevserviceschedule, idservice, idorder, bookingstart, status)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, 'pending')"
|
||||
);
|
||||
$stmt->bind_param("iisiiss", $idnewbooking, $iduser, $prevBookingStart, $idPrevServiceSchedule, $idservicenew, $globalidorder, $newtime);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
|
||||
// Incrementa il contatore riprogrammazioni sull'ordine
|
||||
$stmt = $conn->prepare("UPDATE orderbook SET reprogrammed = reprogrammed + 1 WHERE idorderbook = ?");
|
||||
$stmt->bind_param("i", $globalidorder);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
|
||||
// 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();
|
||||
|
||||
$newtimeformat = date("d-m-Y H:i", strtotime($newtime));
|
||||
|
||||
// Se manca l'email, completa comunque il flusso senza inviare
|
||||
if ($emailuser === '') {
|
||||
header("Location: userpanel.php?reprogram=Y");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Contenuto mail
|
||||
$messageedit = " <p style='font-size: 14px; line-height: 190%;'><span style='font-size: 18px; line-height: 34.2px;'><strong><span style='line-height: 34.2px; font-size: 18px;'> Ciao $firstname , </span></strong></span></p>
|
||||
<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 16px; line-height: 30.4px;'>Hai inviato una richiesta di riprogrammazione della tua lezione </span></p>
|
||||
<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 16px; line-height: 30.4px;'>Ecco il dettaglio della riprogrammazione $newtimeformat</span></p>
|
||||
<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 16px; line-height: 30.4px;'>La tua richiesta è in fase di accettazione! Verrai avvisata se la riprogrammazione è stata accettata</span></p>
|
||||
@@ -76,49 +107,36 @@ $messageedit=" <p style='font-size: 14px; line-height: 190%;'><span style='fo
|
||||
<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 16px; line-height: 30.4px;'>Ci vediamo sul tappetino!</span></p>
|
||||
<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 16px; line-height: 30.4px;'>Il Team Yogasoul</span></p>";
|
||||
|
||||
$buttonedit="<a href='https://yogibook.yogasoul.it/' target='_blank' class='v-button v-font-size' style='box-sizing: border-box;display: inline-block;text-decoration: none;-webkit-text-size-adjust: none;text-align: center;color: #FFFFFF; background-color: #3AAEE0; border-radius: 4px;-webkit-border-radius: 4px; -moz-border-radius: 4px; width:auto; max-width:100%; overflow-wrap: break-word; word-break: break-word; word-wrap:break-word; mso-border-alt: none;font-size: 14px;'>
|
||||
$buttonedit = "<a href='https://yogibook.yogasoul.it/' target='_blank' class='v-button v-font-size' style='box-sizing: border-box;display: inline-block;text-decoration: none;-webkit-text-size-adjust: none;text-align: center;color: #FFFFFF; background-color: #3AAEE0; border-radius: 4px;-webkit-border-radius: 4px; -moz-border-radius: 4px; width:auto; max-width:100%; overflow-wrap: break-word; word-break: break-word; word-wrap:break-word; mso-border-alt: none;font-size: 14px;'>
|
||||
<span style='display:block;padding:10px 20px;line-height:120%;'><span style='line-height: 16.8px;'>YogiBook - YogaSoul</span></span>
|
||||
</a>";
|
||||
|
||||
|
||||
$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';
|
||||
|
||||
</a>";
|
||||
|
||||
include('mail/emailtemplate2.php');
|
||||
// Email body content
|
||||
$htmlContent = $mailmessage1;
|
||||
|
||||
//$trfnmbmail=$appformn.'r'.$revnumb;
|
||||
$htmlContent = $mailmessage1;
|
||||
|
||||
|
||||
$mail->From = 'info@yogasoul.it';
|
||||
$mail->FromName = 'YogiBook [YogaSoul]';
|
||||
$mail->addAddress($emailuser); // Add a recipient
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
try {
|
||||
$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'];
|
||||
$mail->Port = (int) $_ENV['MAIL_PORT'];
|
||||
$mail->CharSet = 'UTF-8';
|
||||
$mail->isHTML(true);
|
||||
|
||||
|
||||
$mail->setFrom($_ENV['MAIL_FROM_ADDRESS'], $_ENV['MAIL_FROM_NAME']);
|
||||
$mail->addAddress($emailuser);
|
||||
|
||||
$mail->Subject = "Proposta di riprogrammazione!";
|
||||
$mail->Body = $htmlContent;
|
||||
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
|
||||
$mail->Subject = "Proposta di riprogrammazione!";
|
||||
$mail->Body = $htmlContent;
|
||||
$mail->AltBody = 'Hai inviato una richiesta di riprogrammazione. La tua richiesta è in fase di accettazione.';
|
||||
|
||||
$mail->send();
|
||||
|
||||
//mail sent
|
||||
|
||||
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log("Errore invio mail riprogrammazione (iduser $iduser): " . $mail->ErrorInfo);
|
||||
}
|
||||
|
||||
// Esegui il reindirizzamento
|
||||
header("Location: userpanel.php?reprogram=Y");
|
||||
exit();
|
||||
}
|
||||
?>
|
||||
header("Location: userpanel.php?reprogram=Y");
|
||||
exit();
|
||||
|
||||
Reference in New Issue
Block a user