I have created a html application form in which I have integrated razor payment gateway after the user pays it will send a mail that application recieved. My issue is out of 12 , 2 or 3 datas are missing in the database and also they didn’t recieved any mail . I hosted this in vps server contabo how to resolve from this ?
<?php
session_start();
$servername = "173.212.211";
$username = "root";
$password = "";
$database = "contactsams";
$errors = [];
$conn = new mysqli($servername, $username, $password, $database);
try {
if ($conn->connect_error) {
throw new Exception("Connection failed: " . $conn->connect_error);
}
} catch (Exception $e) {
$errors[] = $e->getMessage();
}
function generateApplicationID($conn)
{
$currentYear = date("Y");
$result = $conn->query("SELECT COUNT(*) AS count FROM admissions");
$row = $result->fetch_assoc();
$count = $row["count"] + 1001;
$applicationID = "SAMS-" . $count . "-" . $currentYear;
return $applicationID;
}
require "./vendor/phpmailer/phpmailer/src/Exception.php";
require "./vendor/phpmailer/phpmailer/src/PHPMailer.php";
require "./vendor/phpmailer/phpmailer/src/SMTP.php";
use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;
$autoloadPath = __DIR__ . "/vendor/autoload.php";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$firstName = mysqli_real_escape_string($conn, $_POST["first_name"]);
$lastName = mysqli_real_escape_string($conn, $_POST["last_name"]);
$phoneNumber = mysqli_real_escape_string($conn, $_POST["phone_number"]);
$dob = mysqli_real_escape_string($conn, $_POST["dob"]);
$email = mysqli_real_escape_string($conn, $_POST["email"]);
$fatherName = mysqli_real_escape_string($conn, $_POST["father_name"]);
$motherName = mysqli_real_escape_string($conn, $_POST["mother_name"]);
$parentPhoneNumber = mysqli_real_escape_string(
$conn,
$_POST["parent_phone_number"]
);
$selectedCourse = mysqli_real_escape_string($conn, $_POST["course"]);
$selectedCourseList = mysqli_real_escape_string(
$conn,
$_POST["course_list"]
);
$highestQualification = mysqli_real_escape_string(
$conn,
$_POST["highest_qualification"]
);
if (empty($fatherName)) {
$errors[] = "All fields are required.";
}
if (empty($errors)) {
try {
$applicationID = generateApplicationID($conn);
$sql = "INSERT INTO admissions (application_id, first_name, last_name, phone_number, dob, email, father_name, mother_name, parent_phone_number, selected_course, selected_course_list, highest_qualification)
VALUES ('$applicationID', '$firstName', '$lastName', '$phoneNumber', '$dob', '$email', '$fatherName', '$motherName', '$parentPhoneNumber', '$selectedCourse', '$selectedCourseList', '$highestQualification')";
if ($conn->query($sql) === true) {
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = "[email protected]";
$mail->Password = "oaknqyyadwpkkmal";
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$htmlContent =
'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Email</title>
</head>
<body style="margin: 0; padding: 0; font-family: Arial, sans-serif; background-color: white;">
<div style="background-color: #27538c; padding: 20px; text-align: center;">
<p style="font-size: 14px; color: #ffffff;">WE HAVE RECEIVED YOUR APPLICATION FORM! THANK YOU!</p>
</div>
<div style="margin-top: 20px; text-align: center;">
<img src="https://i.ibb.co/1fGCtnH/image-1.png" alt="img" style="display: block; margin: 0 auto;">
<p style="font-size: 28px; font-weight: bold; margin-top: 20px;">Thank you</p>
<p style="font-size: 28px; font-weight: bold;">For Choosing SAMS</p>
</div>
<div style="margin: 20px 0 40px 0; padding: 20px; background-color: #ffffff;">
<p style="font-size: 16px; margin-bottom: 10px;">Dear Prospective Student,</p>
<p style="font-size: 16px; margin-bottom: 10px;">Thanks for choosing SAMS .</p>
<p style="font-size: 16px; margin-bottom: 10px;">Your Application ID: [' .
$applicationID .
']</p>
<p style="font-size: 16px; margin-bottom: 10px;">Kindly use the above ID for further process.</p>
<p style="font-size: 16px; margin-bottom: 10px;">Your Chosen Course: [' .
$selectedCourseList .
']</p>
<p style="font-size: 16px; margin-top: 10px;">Do You Want To Register For IMU- CET Training? <a
href="https://forms.gle/5Nmk3ydJnD4MwkMS6" target="_blank"
style="text-decoration: none; color: white; background-color: #26528c; padding: 3px 7px ; border-radius: 5px;">YES</a>
</p>
<div style="display: flex; flex-direction:column; margin-top: 20px;">
<a href="https://wa.link/4w4det"
style="padding: 10px 20px; background-color: #26528c; color: #ffffff; text-decoration: none; border-radius: 5px;">Whatsapp
Maritime Studies</a>
<a href="https://wa.link/336b2x"
style="padding: 10px 20px; background-color: #26528c; color: #ffffff; text-decoration: none; border-radius: 5px;">Whatsapp
Engineering Studies</a>
</div>
</div>
<div style="background-color: #26528c; color: #ffffff; padding: 20px;">
<p style="font-size: 24px; margin-bottom: 10px;">Thanks for the support! ????</p>
<p style="font-size: 16px; margin-bottom: 10px;">College Location:<br>
82, Panapakkam, Near Periyapalayam, Chennai Thirupathi Road, Uthukottai, Taluk, Thiruvallur District, Near
Honda Factory, Chennai, Tamil Nadu 601102.</p>
<div style="display: flex; flex-direction:column;">
<p style="font-size: 16px;">Phone Number: <a href="tel:8925832436"
style="color: #fbeeb8; text-decoration: underline;">8925832436</a></p>
<p style="font-size: 16px;">Email: <a href="mailto:[email protected]"
style="color: #fbeeb8; text-decoration: underline;">[email protected]</a></p>
</div>
</div>
</body>
</html>
';
$mail->setFrom("[email protected]", "SAMS");
$mail->addAddress($email, $firstName);
$mail->Subject = "Application Confirmation";
$mail->Body = $htmlContent;
$mail->isHTML(true);
$mail->Body = $htmlContent;
$mail->ContentType = "text/html";
$mail->send();
} catch (Exception $e) {
$errors[] =
"Email could not be sent. Mailer Error: " .
$mail->ErrorInfo;
}
header("Location: thankyou.html");
exit();
} else {
throw new Exception("Error: " . $sql . "<br>" . $conn->error);
}
} catch (Exception $e) {
$errors[] = $e->getMessage();
}
}
}
$conn->close();
if (!empty($errors)) {
foreach ($errors as $error) {
echo $error . "<br>";
}
}
?>
New contributor
Bala Subramanian A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.