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 = "[email protected]";
$mail->FromName = "Elvis ";
//To address and name
$mail->addAddress("[email protected]", "Elvis");
$mail->addAddress("[email protected]"); //Recipient name is optional
//Address to which recipient will reply
$mail->addReplyTo("[email protected]", "Reply");
//CC and BCC
//$mail->addCC("[email protected]");
//$mail->addBCC("[email protected]");
//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.
You're sending using the default mail()
transport, which means messages are sent through your local mail server, so look in its logs, usually somewhere like /var/log/mail.log
, and that will tell you what happens to messages after you've submitted them.