PHPMailer cannot send email

前端 未结 2 1975
粉色の甜心
粉色の甜心 2020-12-07 06:01

My project contains a function to send email, being PHPMailer. It runs well to send email from my localhost server, but it stopped sending email today, and now

相关标签:
2条回答
  • 2020-12-07 06:32

    This is commonly reported as a PHPMailer problem (and there are many duplicates of this question), but it's almost always down to local DNS failure, firewall blocking or other network issue on your local network.

    First, make sure you are using the latest PHPMailer.

    Don't use SSL on port 465, it's been deprecated since 1998 and is only used by Microsoft products that didn't get the memo; use TLS on port 587 instead:

    $mail->SMTPSecure = 'tls';
    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 587;
    

    or more succinctly:

    $mail->Host = 'tls://smtp.gmail.com:587';
    

    You can your connectivity this by running some commands on your server (you will need dnsutils and telnet packages installed). First check DNS is working:

    dig +short smtp.gmail.com
    

    You will get something like this if your DNS is working:

    gmail-smtp-msa.l.google.com.
    173.194.67.108
    173.194.67.109
    

    Next try to telnet to the host on the port you need:

    telnet smtp.gmail.com 587
    

    This should give you something like this:

    Trying 173.194.67.109...
    Connected to gmail-smtp-msa.l.google.com.
    Escape character is '^]'.
    220 mx.google.com ESMTP ex2sm16805587wjd.30 - gsmtp
    

    (Enter quit to get out of that).

    If either of these fail, PHPMailer will not work either. So go fix your network, then try again. If you are not in control of your own firewall or DNS, you probably need to raise a support ticket with your ISP to fix this. If they won't fix it, you need to replace your ISP.

    Back in PHPMailer, you can get lower-level feedback on the connection by setting:

    $mail->SMTPDebug = 4;
    
    0 讨论(0)
  • 2020-12-07 06:53

    A simple google search revealed this forum - http://forums.devshed.com/php-development-5/unable-to-find-the-socket-transport-ssl-667689.html

    0 讨论(0)
提交回复
热议问题