Uncaught Error: Failed opening required ‘PHPMailerAutoload.php’
Warning: require(PHPMailerAutoload.php): Failed to open stream:
I am trying to send an email using PHP, whenever I want to send an email but the email is not sent through and I think it is because the composer is not installed.
I want my site to send a student email after registration.
<?php
require 'PHPMailer/PHPMailer/PHPMailerAutoload.php';
require 'PHPMailer/PHPMailer/class.smtp.php';
require 'PHPMailer/PHPMailer/class.phpmailer.php';
use PHPMailerPHPMailerPHPMailer;
include('database/config.php');
if (isset($_POST['submit'])) {
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$Gender = $_POST['Program'];
$Email = $_POST['Email'];
$Subject1 = $_POST['Subject1'];
$Subject2 = $_POST['Subject2'];
$Address = $_POST['Address'];
$ContactNum = $_POST['ContactNum'];
$Password = $_POST['password'];
$hashed_password = password_hash($Password, PASSWORD_DEFAULT);
$reference = $_POST['reference'];
$proof = $_FILES['proof']['name'];
$tmp_name = $_FILES['proof']['tmp_name'];
$target_dir = "uploads/";
$target_file = $target_dir . basename($proof);
if (move_uploaded_file($tmp_name, $target_file)) {
$Actions = "Pending";
$checkQuery = "SELECT COUNT(*) as count FROM Students WHERE Email = '$Email'";
$result = $conn->query($checkQuery);
$row = $result->fetch_assoc();
if ($row['count'] > 0) {
// Email already exists, display error message or take appropriate action
} else {
$sql = "INSERT INTO Students (FirstName, LastName, Subject1, Subject2, Email, Address, ContactNum, Password,Actions,reference,proof) VALUES ('$FirstName', '$LastName', '$Subject1', '$Subject2', '$Email', '$Address', '$ContactNum', '$hashed_password', '$Actions','$reference', '$proof')";
if ($conn->query($sql) === TRUE) {
// Send email
$mail = new PHPMailer(true);
try {
//Server settings
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = '*********'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('[email protected]', 'DSI TUTORING');
$mail->addAddress($Email, $FirstName . ' ' . $LastName); // Add a recipient
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Registration Confirmation';
$mail->Body = 'Dear ' . $FirstName . ',<br><br>Thank you for registering. Your registration is pending approval.<br><br>Best regards,<br>Your Organization';
if ($mail->send()) {
// Redirect to thank you page
$_SESSION['user_id'] = $conn->insert_id;
header("Location: thank_you.php");
exit;
}
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();
}
}
?>