【问题标题】:SMTP server response: 530 5.7.0 Must issue a STARTTLS command firstSMTP 服务器响应:530 5.7.0 必须先发出 STARTTLS 命令
【发布时间】:2011-07-13 01:10:37
【问题描述】:

SMTP 服务器响应:530 5.7.0 必须先发出 STARTTLS 命令

当我在 php 脚本文件中使用 mail() 函数时收到此错误消息...

我使用的是 gmail SMTP 服务器,而 gmail 使用的是安全 SSL 的 STARTTLS 我已经在我的contact.php文件中使用了这些命令

ini_set("SMTP","smtp.gmail.com");
ini_set("sendmail_from","<email-address>@gmail.com>");

那么我可以使用什么命令来启用 STARTTLS 或在 php,ini 文件中配置??

【问题讨论】:

标签: php smtp


【解决方案1】:

我知道PHPMailer 库可以处理那种 SMTP 事务。

此外,带有 sendmail-SSL 库的虚假 sendmail 应该可以完成这项工作。

【讨论】:

    【解决方案2】:

    首先,确保您的 PHP 安装支持 SSL(在 phpinfo() 的输出中查找“openssl”部分)。

    您可以在 PHP.ini 中设置以下设置:

    ini_set("SMTP","ssl://smtp.gmail.com");
    ini_set("smtp_port","465");
    

    【讨论】:

    • 你知道其他免费邮件服务器网站吗?其中不需要 ssl。
    • 或者,使用带有端口 587 的 tls://smtp.gmail.com
    • 无法在“ssl://smtp.gmail.com”端口 465 连接到邮件服务器,
    【解决方案3】:

    就我而言,Swift Mailer 也帮不上忙。我在这里找到了一个解决方案:http://forum.powweb.com/showthread.php?t=73406 - 所以在 EHLO 命令之后,需要发送 STARTTLS 命令,使用stream_socket_enable_crypto( $connection, true, STREAM_CRYPTO_METHOD_TLS_CLIENT ); 启用加密,然后再次使用 EHLO 命令。只有这样,我才能使用“顽固”的 SMTP 服务器发送电子邮件。

    【讨论】:

      【解决方案4】:

      开箱即用的 Swift Mailer 无法执行 STARTTLS,但是有些 nice guys have written a patch for it

      我发现修补它有点麻烦(可能是错误的方式),所以把它压缩起来准备在这里下载:Swift Mailer with STARTTLS

      【讨论】:

      • 版本说明: 从 SwiftMailer v5 开始,它支持开箱即用的 STARTTLS。创建传输实例时添加setEncrpyion('tls')setEncryption('ssl')。阅读more
      【解决方案5】:

      我对以下内容的回答是错误的:

      fputs($connection, 'STARTTLS'.$newLine);
      

      原来我使用了错误的连接变量,所以我只需要将其更改为:

      fputs($smtpConnect, 'STARTTLS'.$newLine);
      

      如果使用 TLS,记得在前后放置 HELO:

      fputs($smtpConnect, 'HELO '.$localhost . $newLine);
      $response = fgets($smtpConnect, 515);
      if($secure == 'tls')
      {
          fputs($smtpConnect, 'STARTTLS'.$newLine);
          $response = fgets($smtpConnect, 515);
      stream_socket_enable_crypto($smtpConnect, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
      
      // Say hello again!
          fputs($smtpConnect, 'HELO '.$localhost . $newLine);
          $response = fgets($smtpConnect, 515);
      }
      

      【讨论】:

        【解决方案6】:

        问题已解决,

        我编辑了文件/etc/postfix/master.cf

        并发表评论

        -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
        

        并从

        更改了行
        -o smtpd_tls_security_level=encrypt 
        

        -o smtpd_tls_security_level=may
        

        并且工作得很好

        【讨论】:

        • 请解释一下你到底在做什么,我也不确定这会解决 OP 的问题,因为他可能无权访问你在这里编辑的文件
        • 此配置允许 Postfix 发送非加密电子邮件,即您通过 smtp 进行身份验证但发送不可靠的消息。
        【解决方案7】:

        块引用

        I then modified the php.ini file to use it (commented out the other lines):
        
        [mail function]
        ; For Win32 only.
        ; SMTP = smtp.gmail.com
        ; smtp_port = 25
        
        ; For Win32 only.
        ; sendmail_from = <e-mail username>@gmail.com
        
        ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
        sendmail_path = "C:\xampp\sendmail\sendmail.exe -t"
        
        Ignore the "For Unix only" comment, as this version of sendmail works for Windows.
        
        You then have to configure the "sendmail.ini" file in the directory where sendmail was installed:
        
        [sendmail]
        
        smtp_server=smtp.gmail.com
        smtp_port=25
        error_logfile=error.log
        debug_logfile=debug.log
        auth_username=<username>
        auth_password=<password>
        force_sender=<e-mail username>@gmail.com
        
        http://byitcurious.blogspot.com.br/2009/04/solving-must-issue-starttls-command.html
        
        > Blockquote
        

        【讨论】:

          【解决方案8】:

          我将分享我的方法,它在实施以下操作后对我有用:

          打开 Php.ini 文件并通过从 Gmail SMTP Settings 获取 ref 填充各个字段中的所有值

          从 [mail function] 中删除 cmets,这些语句是对 smtp 服务器的指令并匹配它们的值。

          sendmail SMTP 服务器也是假服务器。它除了文本终端之外什么都没有(尝试在上面写任何东西。:P)。 它将使用 gmail s,tp 发送邮件。 所以通过匹配 Gmail SMTP 设置来正确配置它:

          smtp.gmail.com
          Port: 587
          

          【讨论】:

            【解决方案9】:

            对于 Windows,我可以通过启用 TLS 在 SMTP 虚拟服务器上进行安全通信来使其正常工作。没有证书的 SMTP 虚拟服务器上将无法使用 TLS。此链接将提供所需的步骤。

            https://support.microsoft.com/en-ie/help/4014125/how-to-configure-iis-smtp-for-outgoing-tls-authentication

            【讨论】:

            • 仅链接的答案并不理想。您应该引用和评论链接的相关部分,以使其成为一个独立的答案。
            【解决方案10】:
            //The challenge is with Create the Transport .  Replace the following
            
             $transport = (new Swift_SmtpTransport('smtp.gmail.com', 587))
                    ->setUsername('xxxxxxxxx@gmail.com')
                    ->setPassword('xxxxxxxxx');
            
            
            ////With the following lines of codes
            
            
                     //new Create the Transport
                $transport = (new Swift_SmtpTransport('smtp.googlemail.com', 465, 'ssl'))
                  ->setUsername('xxxxxxxxx@gmail.com')
                  ->setPassword('xxxxxx');
            

            【讨论】:

              猜你喜欢
              • 2014-06-27
              • 2016-05-16
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2015-02-04
              • 1970-01-01
              • 2016-04-07
              • 1970-01-01
              相关资源
              最近更新 更多