SMTP错误:EHLO命令失败:-ERR未知命令

时间:2018-12-09 20:56:22

标签: php

我正在尝试使用以下PHP代码发送电子邮件:

        require("PHPMailer-master/src/PHPMailer.php");
        require("PHPMailer-master/src/SMTP.php");
        require("PHPMailer-master/src/Exception.php");

        $from  = "admin@mydomain.com";
        $namefrom = "admin";
        $mail = new PHPMailer\PHPMailer\PHPMailer();
        $mail->isSMTP();   // by SMTP
        $mail->SMTPDebug = 1;
        $mail->SMTPAuth   = true;   // user and password
        $mail->Host       = "mail.gandi.net";
        $mail->Port       = 110;
        $mail->Username   = $from;
        $mail->Password   = "Password123";

        $mail->CharSet = 'UTF-8';
//        $mail->SMTPSecure = "";    // options: 'ssl', 'tls' , ''  
        $mail->setFrom($from,$namefrom);   // From (origin)
        $mail->addCC($from,$namefrom);      // There is also addBCC
        $mail->Subject  = "Some subject";
        $mail->AltBody  = "Altenrate";
        $mail->Body = "Heyheyhey";
        $mail->isHTML(false);   // Set HTML type
        $mail->addAddress("hello@hotmail.com", "hello@hotmail.com");
        if($mail->send())
        {
          echo "ok sent";
        }
        else
        {
             echo "Mailer Error: " . $mail->ErrorInfo;
        }

    }

使用此代码时,需要花一些时间才能加载,最终向我显示此错误:

2018-12-09 20:50:24 CLIENT -> SERVER: EHLO www.mydomain.be
2018-12-09 20:53:24 SMTP ERROR: EHLO command failed: -ERR Unknown command.-ERR Disconnected for inactivity.
2018-12-09 20:53:24 SMTP NOTICE: EOF caught while checking if connected
SMTP Error: Could not authenticate.
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

有人可以向我解释这个问题是什么以及如何解决它?

谢谢!

2 个答案:

答案 0 :(得分:0)

根据:https://docs.gandi.net/en/gandimail/standard_email_settings/index.html

您的设置有误

应该是

Outgoing (SMTP) server name: mail.gandi.net
Port: 25, 465 (with SSL) or 587 (with STARTTLS)
TLS or SSL: yes
SMTP Authentication: yes, using the same settings as for the POP / IMAP account

答案 1 :(得分:0)

Hello traducerad,

(x 25)

端口110用于传入POP通信。
我认为您想通过SMTP发送电子邮件。

  

发送(SMTP)服务器名称:mail.gandi.net
  端口:25、465(使用SSL)或587(使用STARTTLS)
  TLS或SSL:是
  SMTP身份验证:是,使用与POP / IMAP帐户相同的设置

FAQ from gandi.net