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.
My Answer:
> It is possible that there is nothing wrong with your code and the delay in sending the first email could be due to various factors such as network issues, server load, or email server processing time. However, there are a few things you can try to improve the delivery time of the first email:
1. Check your server's email sending capabilities and make sure it is properly configured to send emails efficiently.
2. Make sure your email server is not blacklisted or marked as spam by the recipient's email server.
3. Consider using a third-party email delivery service like SendGrid or Amazon SES for more reliable and faster email delivery.
4. Check the email headers of the delayed emails to see if there are any clues as to why they are taking longer to arrive.
5. Experiment with different SMTP settings in PHPMailer to see if that improves the delivery time.
If none of these suggestions help, it may be worth reaching out to your email hosting provider or server administrator for further assistance.
Rate this post
3 of 5 based on 2091 votesComments