PHPMailer too slow to send emails

1

I'm using PHPMailer on a GoDaddy host, the registration page takes about 10 ~ 15 seconds just to send the email, is there any efficient way to optimize this? or is it a matter of server capacity?

Current setting:

    $Mailer = new PHPMailer;

    $Mailer -> isSMTP();
    $Mailer -> CharSet = MAIL_CHARSET;
    $Mailer -> SMTPSecure = MAIL_SECURE;
    $Mailer -> Host = MAIL_HOST;
    $Mailer -> Port = MAIL_SMTP_PORT;
    $Mailer -> SMTPAuth = true;

    $Mailer -> Username = MAIL_USER;
    $Mailer -> Password = MAIL_PASSWORD;

    // REMETENTE
    $Mailer -> From = 'xxxxxxx';
    $Mailer -> FromName = 'xxxxxx';
    //CORPO DA MSG
    $Mailer -> Subject = $title;
    $Mailer -> msgHTML($message);
    $Mailer -> isHTML(true);

    // DESTINATÁRIO
    $Mailer -> addAddress($email);
    
asked by anonymous 07.12.2016 / 06:15

1 answer

2

It's a very high time even for an authenticated email. Usually 1 to 4 seconds is something reasonable but still uncomfortable. In the meantime the user becomes anxious and impatient. It has to refresh the page, make duplicate submissions, etc., generating even more traffic.

One tactic to reduce this time-out cost on the user side is to generate a schedule on the server to send immediately after the first minute. So the request will return to the user's browser in a few milliseconds. In the meantime, the scheduling on the server will "take care" of the execution. Alternatively the scheduling is to create a background execution because schedules depend on the permissions of the hosting server.

On the problem described in the question it is unfeasible to determine what actually happens. It can be poor server environment configuration or simply limited capacity.
Due to the high wait time, I suggest that you consult the server support because it is not a normal wait time even on cheap shared servers.

Also be aware that email authentication depends on a third party server, the SMTP server you are authenticating with, so it may be a failure or congestion on that SMTP server and may be momentary. You can test this by configuring sending to other SMTP servers. For example, if you are dealing with gmail, test with live mail, yahoo or any other private. If everyone else takes a lot of time, then it is likely that there is something "abnormal" on the hosting server.

Either way, sending e-mail always takes a while. Try creating scheduling or background (asynchronous) execution techniques.

For asynchronous execution, see: Run parallel process in PHP

    
07.12.2016 / 07:35