PHPMailer slow on sending emails

the mail() function

Moderators: macek, egami, gesf

RYMK0087
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Oct 08, 2013 5:38 am

PHPMailer slow on sending emails

Postby RYMK0087 » Tue Oct 08, 2013 5:51 am

Hi everyone,

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.

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: PHPMailer slow on sending emails

Postby johnj » Fri Oct 11, 2013 11:42 pm

1).Check if you have any other software that is intefering with the mailer

2).You need to debug line by line to make sure where exactly the problem is?

3).Does your Apache version match with the version of php mailer...please check?

4).Is there any other software running on your server which is sharing port 465?

5).Check your logs for unusual behavior.

RYMK0087
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Oct 08, 2013 5:38 am

Re: PHPMailer slow on sending emails

Postby RYMK0087 » Sun Oct 20, 2013 11:09 pm

Sorry for the late reply, I was away for the week. And thanks for the reply.

For general info, here are the version of what I have installed:
Apache/2.2.25 (Win32) - mod_ssl/2.2.25 - OpenSSL/0.9.8y - PHP/5.4.17 - PHPMailer for PHP5/6


2).You need to debug line by line to make sure where exactly the problem is?

I already did and most of the delay is at the authentication line. When I commented that out, the emails going through took one second or less. So it's this line:

Code: Select all

$mail->SMTPAuth = true;


3).Does your Apache version match with the version of php mailer...please check?

Is there a standard way to check this? I tried some research but came out blank.

4).Is there any other software running on your server which is sharing port 465?

I checked and Thunderbird was using that port for outgoing mail. I changed that for testing and the delay was reduced by one second, though there was still a delay. Does this mean that several issues are at play here?

5).Check your logs for unusual behavior.

In Apache error logs, I see the following line on each restart:
PHP Warning: PHP Startup: smtp: Unable to initialize module\nModule compiled with module API=20060613\nPHP compiled with module API=20100525\nThese options need to match\n in Unknown on line 0


I've seen that this could be an issue with module that aren't upgrades on PHP upgrade but my PHP version was the same from the first installation. Any ideas what else it could be?

Thanks for your time.

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: PHPMailer slow on sending emails

Postby johnj » Tue Oct 22, 2013 5:16 am

check your send mail settings in php.ini

RYMK0087
New php-forum User
New php-forum User
Posts: 5
Joined: Tue Oct 08, 2013 5:38 am

Re: PHPMailer slow on sending emails

Postby RYMK0087 » Wed Oct 23, 2013 3:21 am

It is as follows:

Code: Select all

SMTP = smtp.gmail.com
smtp_port = 465
sendmail_from = myGmailAddress


Note: I got one second faster sending by substituting the below:

Code: Select all

$mail->Username = "myUsername@gmail.com";

With

Code: Select all

$mail->Username = "myUsername";


Since it's the username that's required not the whole address.


Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 1 guest

cron