I don't know why, but phpmailer, when sending first email to a particular email address takes up to 5minutes-2hours to arrive in inbox sometimes it never comes until you send a second mail.
But after the first email is received in inbox, subsequent mails to that particular email comes within seconds.
Could there be anything wrong with my code or there's something I'm doing wrong somewhere?
function loadMailData(array $mailData){
$website = new \core\Website();
$mail = new PHPMailer();
//Enable SMTP debugging.
// $mail->SMTPDebug = 3;
// $mail->SMTPDebug = SMTP::DEBUG_SERVER;
//Set PHPMailer to use SMTP.
$mail->isSMTP();
//Set SMTP host name
$mail->Host = $this->stmpHost;
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;
//Provide username and password
$mail->Username = $this->smtpUsername;
$mail->Password = $this->smtpPassword;
//If SMTP requires TLS encryption then set it
// $mail->SMTPSecure = "ssl";
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
//Set TCP port to connect to
$mail->Port = 465;
$mail->From = $mailData['sentBy'];
$mail->FromName = $website->name;
$mail->AddReplyTo($this->replyTo, 'Support');
$mail->smtpConnect(
array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
"allow_self_signed" => true
)
)
);
$mail->addAddress($mailData['email']);
$mail->isHTML(true);
$mail->Subject = $mailData['subject'];
$mail->Body = $mailData['message'];
//$mail->AltBody = "This is the plain text version of the email content";
if($mail->send()){
//echo "Message has been sent successfully";
return true;
}else{
//echo "Mailer Error: " . $mail->ErrorInfo;
return false;
}
}
:::::::::UPDATE::::::::
I Just tried sending an email from my hosting server's webmail and it went within seconds. Unlike when I use phpMailer with the webmail's config as smtp.
Currently, my emails don't even arrive on time any more be it the first or second or 3rd. Takes upto 3hrs sometimes
It's kind if frustrating.