I'm getting the error : Class 'PHPMailer' not found in PHPMailer
I know the answer is probably out there but for my code, I can't seem to work it out.
I have a .php file where I created a class called Email, then a function inside this called sendEmail. Inside this function there is the PHPMailer files and code to send an email.
My code is :
function sendMail($con, $siteName, $siteLogo, $email1, $email2, $email3, $email4, $email5, $title, $message, $buttonText, $buttonLink) {
# Get the variables of the email using the variables inside the function's brackets upon request
error_reporting(E_ALL);
global $gmailEmail;
global $gmailPassword;
global $siteUrl;
require $siteUrl.'PHPMailer/PHPMailer.php';
require $siteUrl.'PHPMailer/SMTP.php';
require $siteUrl.'PHPMailer/Exception.php';
$mail = new PHPMailer;
$body = $this->emailTemplate($con, $siteName, $siteLogo, $email1, $email2, $email3, $email4, $email5, $title, $message, $buttonText, $buttonLink);
$mail->Host = "smtp.gmail.com";
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = $gmailEmail;
$mail->Password = $gmailPassword;
$mail->SetFrom("admin@".$siteName, $sitename." Admin");
$mail->AddReplyTo("admin@".$siteName, $sitename." Admin");
$mail->Subject = $title;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$emails = array($email1, $email2, $email3, $email4, $email5);
# Foreach email that is not empty, send the email
foreach((array)$emails as $email) {
$mail->AddAddress($email);
if (!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
}
}
But the error lies on the line of the code: $mail = new PHPMailer;
, saying Class 'PHPMailer' not found
Someone said it's the use's :
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
But whenever I include these, I get this error: Class 'PHPMailer\PHPMailer\PHPMailer' not found