PHPMailer using Gmail SMTP slow when sending emails

后端 未结 6 1464
礼貌的吻别
礼貌的吻别 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:49

    The slowness (or failure due to timeouts) is because Google supports IPv6 addressing but your network does not. (e.g. Digital Ocean does not yet support IPv6 for SMTP traffic). So, use this:

    $mail->Host = gethostbyname("smtp.gmail.com");
    

    gethostbyname() will return the IPv4 address.

    For me, my PHPMailer script went from ~2 minutes execution time to <4 seconds

提交回复
热议问题