Phpmailer too slow to send emails

Asked

Viewed 1,145 times

1

I’m using the PHPMailer on a Godaddy host, the sign-up 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 configuration:

    $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);

1 answer

2

It is a very high time even for an authenticated email. Normally 1 to 4 seconds is reasonable but still uncomfortable. In the meantime the user is annoying and impatient. It has to update the page, makes duplicate submissions, etc, generating even more traffic.

One tactic to reduce this cost of waiting time on the user’s side is to generate a server schedule to send right away in the first minute. So the request will return to the user’s browser in a few milliseconds. Meanwhile, the scheduling on the server will "take care" of the execution. Alternatively to scheduling is to create a background run because schedules depend on hosting server permissions.

About the problem described in the question it is impossible to determine what really happens. It can be bad server environment configuration or simply a limited capacity.
Due to the high waiting time, I suggest you refer to server support as it is not a normal waiting time even on cheap shared servers.

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

Anyway, sending email always costs a while. Try to create scheduling or background execution techniques (asynchronous).

For asynchronous execution, see: Run parallel process in PHP

  • The test you talk to with gmail, live mail and yahoo mail would be the recipients, right? because I’ve seen some examples of them being used as "host," I don’t quite understand

  • vc seems confused as it is mixing things up.. The test is to replace the sender authentication smtp..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.