I'm using PHPMailer and my site is hosted on GoDaddy. when I'm sending mail it is saying maile sent but in the mailbox, it is not received. I'm getting the message: Fri, 21 Oct 2022 00:25:38 -0700 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
Sometimes on Gmail mail is received but mostly it is not coming also on my domain webmail it is received but on the same mail GSuite it is not received.
below is my code:
Phpmailer_lib.php
<?PHP
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
class PHPMailer_Lib {
public function __construct() {
log_message('Debug','PHPMailer class is loaded');
}
public function load() {
require_once APPPATH.'third_party/PHPMailer/src/Exception.php';
require_once APPPATH.'third_party/PHPMailer/src/PHPMailer.php';
require_once APPPATH.'third_party/PHPMailer/src/SMTP.php';
require APPPATH. 'third_party/PHPMailer/src/PHPMailerAutoload.php';
$mail = new PHPMailer;
return $mail;
}
}
Send mail function
{
$this->load->library('phpmailer_lib');
$mail = $this->phpmailer_lib->load();
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'mail.xyz.com';
$mail->Port = 465;
$mail->Username = 'info@xyz.com';
$mail->Password = '***';
$mail->setFrom('info@xyz.com', 'xyz Info');
$mail->addReplyTo('info@xyz.com', 'xyz Info');
$mail->addAddress('xyz@gmail.com');
$mail->addAddress('random@abc.com');
$mail->addAddress('randon@pqr.com');
$mail->Subject = 'PHPMail subject';
$mail->Body = '<h5>PHPMail body</h5>';
$mail->isHTML(true);
$mail->ErrorInfo;
if($mail->send()) {
echo "Mail sent";
}else {
echo "Mail ERROR";
}
echo $mail->ErrorInfo;
}