Website URL
Error Message
This page isn’t working
cmsystem.infinityfreeapp.com is currently unable to handle this request.
HTTP ERROR 500
Other Information
so i was doing a php mailer on my register but its not working i also dont know what do folders, or php do i need to upload for phpmailer folder i kinda have problem on php mailer
Heres the code for it
<?php
// Include the database connection file
include('db.php');
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
require 'PHPMailer/src/Exception.php';
// Include PHPMailer
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Define error message variables
$usernameErr = $emailErr = $passwordErr = "";
// Register user
if (isset($_POST['register'])) {
// Get form inputs
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
// Validate form inputs
if (empty($username)) {
$usernameErr = "Username is required.";
}
// Email validation
if (empty($email)) {
$emailErr = "Email is required.";
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format.";
} elseif (strpos($email, '@gmail.com') === false) {
$emailErr = "Please use a Gmail address (e.g., [email protected]).";
}
if (empty($password)) {
$passwordErr = "Password is required.";
}
// Check if email already exists in the database
if (empty($usernameErr) && empty($emailErr) && empty($passwordErr)) {
// Check if the email already exists
$stmt = $conn->prepare("SELECT * FROM users WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
// Email already exists
$emailErr = "The email address is already registered.";
} else {
// Hash the password using bcrypt
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
// Generate a random 6-digit verification code
$verification_code = rand(100000, 999999);
// Prepare and execute SQL query to insert user data into the 'users' table
$stmt = $conn->prepare("INSERT INTO users (username, email, password, verification_code) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssss", $username, $email, $hashed_password, $verification_code);
if ($stmt->execute()) {
echo "Registration successful! Please check your email for the verification code.";
// Send verification code to the user's email using PHPMailer
$mail = new PHPMailer(true);
try {
// Server settings
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com'; // Gmail SMTP server
$mail->SMTPAuth = true;
$mail->Username = '123'; // Your full Gmail address
$mail->Password = '123secret'; // If 2FA is enabled, use the App Password here
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587; // Port for TLS
// Recipients
$mail->setFrom('[email protected]', 'Noel Mara'); // Your full Gmail address
$mail->addAddress($email); // Add recipient's Gmail address
// Content
$mail->isHTML(true);
$mail->Subject = 'Email Verification Code';
$mail->Body = 'Your verification code is: ' . $verification_code;
// Send email
$mail->send();
echo 'Verification code sent to ' . $email;
// Redirect to verify_otp.php with the email as a parameter
header("Location: verify_otp.php?email=" . urlencode($email));
exit();
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
} else {
echo "Error: " . $stmt->error;
}
$stmt->close();
}
}
$conn->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Registration</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">
<div class="container d-flex justify-content-center align-items-center min-vh-100">
<div class="row w-100 justify-content-center">
<!-- Column takes 12 on small screens (full width) and 6 on medium and larger screens (half width) -->
<div class="col-12 col-md-6 col-lg-4">
<div class="card shadow">
<div class="card-body">
<h5 class="card-title text-center fs-3 mb-3">User Registration</h5>
<form method="POST" action="register.php">
<!-- Username -->
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" class="form-control" id="username" name="username" required>
<span class="text-danger"><?php echo $usernameErr; ?></span>
</div>
<!-- Email -->
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" name="email" required>
<span class="text-danger"><?php echo $emailErr; ?></span>
</div>
<!-- Password -->
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
<span class="text-danger"><?php echo $passwordErr; ?></span>
</div>
<!-- Submit Button -->
<button type="submit" name="register" class="btn btn-primary w-100">Register</button>
</form>
<hr>
<p class="text-center">Already have an account? <a href="login.php">Login here</a></p>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
My folder