I am quite new to php and i am tying to use php mailer to send emails. y code is giving me a success message but the email is not being delivered. Here is my code.
<?php
use phpmailer\phpmailer\PHPMailer;
use phpmailer\phpmailer\SMTP;
use phpmailer\phpmailer\Exception;
require 'vendor/phpmailer/phpmailer/src/Exception.php';
require 'vendor/phpmailer/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/phpmailer/src/SMTP.php';
//PHPMailer Object
$mail = new PHPMailer;
//From email address and name
$mail->From = "mail@gmail.com";
$mail->FromName = "Elvis ";
//To address and name
$mail->addAddress("mail1@gmail.com", "Elvis");
$mail->addAddress("mail2@gmail.com"); //Recipient name is optional
//Address to which recipient will reply
$mail->addReplyTo("mail1@gmail.com", "Reply");
//CC and BCC
//$mail->addCC("cc@example.com");
//$mail->addBCC("bcc@example.com");
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
i installed phpmailer using composer at first but i was giving me an error PHP Fatal error: Uncaught Error: Class 'PHPMailer' on the logs so i included the files manually.