PHPMailer using Gmail SMTP slow when sending emails

后端 未结 6 1582
礼貌的吻别
礼貌的吻别 2020-12-30 14:17

I found few older threads that have a similar issue but most of them didn\'t have answers or if they had, the suggestions weren\'t relevant in my case.

I had a compl

6条回答
  •  醉话见心
    2020-12-30 14:44

    If the delay between sending the emails is really a critical issue, have you considered implementing a form of multithreading? The delay per message may be the same, but it would essentially be cut in half if you send two enails at a time.

    An easy way to do this would be to implement a queue, and the message is sent via a non-blocking HTTP/SQL call. In this way you could send as many as you like with a minimal delay.

    I also suggest, if possible, find the gmail server with the lowest latency and add it to your hosts file to elimiinate DNS lookups.

    Also some performance hints: You only need to require_once() for the include file, but you're requiring it on every call (as an aside, include_once() is faster). Why not create a $mail object only once and reuse it whenever you need to call sendemail()?

    Also why not pass message1, subject1, etc. as one array and message2, subject2, etc. as a second array? Passing fewing parameters during procedure calls in general (at least in classical programming) tends to speed things up.

    As an aside -- no idea if this is possible -- Perhaps there is a way to maintain a constant connection to smtp.gmail.com. This would eliminate a lot of overhead as well.

    Also, is relaying your messages through your own meial server an option? It'd elimiinate the delay.

    Finally, I came across this response from Google: [Gmail Sending Limits `

    Thank you for your message.
    
        I understand you have a query regarding the Google Apps for Business sending limits. As 
    mentioned     in our Help Center article at http://support.google.com/a/bin/answer.py?hl=en&
    answer=166852,     the daily limitation is 2000 messages in a 24-hour period not day. In general, our 
    servers can tolerate one message per second until sending limits are hit. We really don't 
    have an hourly or minute limitation for sending. If you send messages too quickly you may     
    get rate-limited but the account should not lock out.
    
    By rate-limt, since in general one message per second, if you try to send too many messages per second 
    you may get a message telling you that the message cannot be send or you must wait before sending a 
    message.
    
    `
    

    I'd be happy to write a class that conforms to these limits if you need one. Please let me know, shouldn't take too long.

    Recommendation: Use another email host/relay

提交回复
热议问题