phpmailer and gmail SMTP ERROR: Failed to connect to server: Network is unreachable (101) SMTP connect() failed

前端 未结 4 2072
天命终不由人
天命终不由人 2020-12-03 19:39

I need help please this is my code:

require \'PHPMailerAutoload.php\';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = \"smtp.gmail.com\";
$mail-         


        
相关标签:
4条回答
  • 2020-12-03 20:18

    You might want to start by isolating this problem to determine whether it's truly a network problem; or whether it's specific to PHP mailer or your code. On your server, from a command prompt, try using telnet to connect to smtp.gmail.com on port 587, like so:

    telnet smtp.gmail.com 587
    

    You should see a response from smtp.gmail.com, like so:

    Trying 173.194.74.108...
    Connected to gmail-smtp-msa.l.google.com.
    Escape character is '^]'.
    220 mx.google.com ESMTP f19sm71757226qaq.12 - gsmtp
    

    Do you see this, or does the connection attempt hang and eventually time out? If the connection fails, it could mean that your hosting company is blocking outgoing SMTP connections on port 587.

    0 讨论(0)
  • 2020-12-03 20:18

    The code below:

    $mail->SMTPSecure = 'ssl';
    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 465;
    $mail->Host = 'ssl://smtp.gmail.com:465';
    
    0 讨论(0)
  • 2020-12-03 20:21

    This worked for me:

    change:

      $mail->SMTPSecure = 'ssl';
      $mail->Host = 'smtp.gmail.com';
      $mail->Port = '465';
    

    to

      $mail->SMTPSecure = 'tls';
      $mail->Host = 'smtp.gmail.com';
      $mail->Port = '587';
    
    0 讨论(0)
  • 2020-12-03 20:40

    change

    $mail->SMTPSecure = "tls";

    with

    $mail->SMTPSecure = 'ssl';

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