I am working on updating a PHP/JS project on a local server (Apache) and I switched from the PHP mail function to PHPmailer.
I had a complete setup at one point with PHP mail function and it worked great. However, I had issues with my harddrive and I had to format it and setup the server from scratch. When that was done, PHP mail function became slow. While researching solutions for that, I found that most people recommended PHPmailer. I switched to that but the problem still persisted.
Please find the relevant code below:
Code: Select all
require_once('PHPMailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = myGmailAddress;
$mail->Password = mypassword;
$mail->SetFrom(myGmailAddress, myServiceName);
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AddAddress($email);
if(!$mail->Send()) { return 0; } else { return 1; }
$mail->ClearAddresses();
I don't see any error through debug and messages, it just takes longer than usual to send the email. Is there anything missing in the mailer setup or is there some behind-the-scenes configuration that I should check?
I've already tried turning off the Firewall just to test it, and it's the same. I tried more debugging and it seems the delay is because of SMTPAuth. Can anything be done to keep the authentication but speed up sending the emails?
Any help would be appreciated. Thanks.