【问题标题】:XAMPP Sendmail using Gmail account使用 Gmail 帐户的 XAMPP Sendmail
【发布时间】:2011-06-24 08:05:12
【问题描述】:

我正在尝试通过 XAMPP 配置 Sendmail 以发送电子邮件。在我的 sendmail.ini 中,我有这些设置:

# Set default values for all following accounts.

logfile "C:\xampp\sendmail\sendmail.log
account Gmail
tls on
port 587
tls_certcheck off
host smtp.gmail.com
from myemail@gmail.com
auth on
user myemail06@gmail.com
password mypassword

account default : Gmail

我已经创建了一个这样的测试脚本:

$to = "testemail@btinternet.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$headers = "From: myemail06@gmail.com" . "\r\n";
if (mail($to, $subject, $body, $headers)) {
    echo ("Message successfully sent!");
} else {
    echo ("Message delivery failed...");
}

我收到一条消息说电子邮件已发送但它从未到达并且在我收到的日志中:

sendmail:投递时出错:必须先发出 STARTTLS 命令。

有人知道这里可能是什么问题吗?

提前致谢!

天然气

【问题讨论】:

  • 只有我一个注意到,OP 正在询问 original sendmail - 世界上最著名的邮件传输代理 (info at Wiki),始于 1979 年,虽然大多数答案都是关于 fake sendmail (homepage) - 一个用于开发服务器包的假程序,例如 XAMPP,于 2004 年开始。你们看不到,那个配置文件OP给出的示例与您在答案中给出的配置示例如此不同?奇怪。

标签: email smtp gmail xampp


【解决方案1】:

第 1 步:转到您的 sendmai.ini

A.设置您的 smtpserver 名称。因为我使用 gmail 所以对我来说它是“smtp.gmail.com”

smtp_server=smtp.gmail.com

B.设置您的 SMTP 端口号。对于 gmail,您可以使用“465”

smtp_port=465 
smtp_ssl=ssl

C.最重要的部分是现在。设置密码。您必须生成应用程序密码才能从服务器发送电子邮件。为此,请按照链接中的步骤操作。 *** 不要使用您的 gmail 登录密码。不起作用。您必须生成应用密码。如果您启用了两步验证,请按照以下步骤生成应用密码,否则只需使用您的 gmail 密码。 https://devanswers.co/create-application-specific-password-gmail/

auth_username=hossain.9090@gmail.com
auth_password=wqutwfuevmssmgko

wqutwfuevmssmgko 是我安全生成的密码。

第 2 步:转到 php.ini

A.为 SMTP 和 smtp_port 相应地设置值。保存,别忘了重启apache。

SMTP=localhost
smtp_port=465

【讨论】:

    【解决方案2】:

    2020 年更新

    简化的解决方案: 如果您使用的是 Gmail,则可以设置应用程序专用密码。

    1. 登录您的 gmail 帐户
    2. 选择右上角的标记(圆圈图标)
    3. 点击管理您的 Google 帐户
    4. 在左侧菜单中选择安全
    5. 在登录您的 Google 下 - 点击应用密码
    6. 选择应用:邮件
    7. 选择设备:您选择的设备,我的是 Windows
    8. auth_password 之后将自动生成的密码复制到您的 sendmail.ini 文件中
    9. 保存,重新启动 XAMPP,希望一切顺利

    这个解决方案对我有用,但当然可能还有其他错误阻碍了您的成功,例如更新 xampp/sendmail 文件夹中的文件、正确的端口设置等。

    【讨论】:

      【解决方案3】:

      我找不到一个完整的工作解决方案,所以我在这里为我们编译它以获取源 https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/#

      你还没有完成!最后要做的一件事是获取应用程序密码

      (auth_password=Your-Gmail-Password)

      而不是您的 gmail 帐户密码,如下所示:

      在浏览器上登录您的 gmail 帐户,然后点击右上角的个人资料图标,选择

      “管理您的 Google 帐户”

      ,左栏点击安全,找到框

      “登录 Google”

      点击

      “应用密码”

      ,这里需要为这个xampp在下发送邮件创建密码

      “选择您要为其生成应用密码的应用和设备。”

      生成密码并将生成的密码复制到

      (auth_password=just-generated-password) this in php.ini above-screenshot.

      就是这样,一切都完成了,它现在应该可以为你工作了!

      享受您的邮件!

      【讨论】:

        【解决方案4】:

        只是为了增加已经很好的反应。确保您以管理员身份运行 XAMPP。这就是为我解决的问题。

        【讨论】:

          【解决方案5】:

          这些是最新的 Google SMTP 服务器要求:

          1. Gmail SMTP 服务器地址:smtp.gmail.com
          2. Gmail SMTP 密码:(您的 Gmail 密码)
          3. Gmail SMTP 端口 (TLS):587
          4. Gmail SMTP 端口 (SSL):465
          5. 需要 Gmail SMTP TLS/SSL:

          Google SMTP Requirements

          如果您只使用 SSL,则所需的 Captcha 验证测试会变得复杂,因此我只需将我的 SSL 设置为自动,这将在 SSL 失败时尝试 TLS。

          【讨论】:

            【解决方案6】:

            a) 更改 php.ini 在文件路径“[Drive Letter]:[XAMPP directory]\php”中找到php.ini。例如C:\xampp\php\php.ini

            在您的 php.ini 文件中搜索 sendmail_path 并删除分号“;”在它之前[我的没有路径]。

            [mail function]
            ; For Win32 only.
            
            SMTP = smtp.gmail.com
            
            smtp_port = 25
            
            ; For Win32 only.
            ; http://php.net/sendmail-from
            sendmail_from = [your_gmail_username]@gmail.com
            sendmail_path = "\"C:\xampplite\sendmail\sendmail.exe\" -t"
            

            b) 更改 sendmail.ini 在文件路径中找到 sendmail.ini 是 “[Drive Letter]:[XAMPP directory]\sendmail” 例如C:\xampp\sendmail\sendmail.ini

            将“Mercury”和“A free mail service example”内容注释为 如下图:

             # Mercury  <br/> 
             #account Mercury  <br/> 
             #host localhost  <br/> 
             #from postmaster@localhost  <br/> 
             #auth off  <br/> 
             # A freemail service example  <br/> 
             #account Hotmail  <br/> 
             #tls on  <br/> 
             #tls_certcheck off  <br/> 
             #host smtp.live .com  <br/> 
             #from [exampleuser]@hotmail.com  <br/> 
             #auth on  <br/> 
             #user [exampleuser]@hotmail .com  <br/> 
             #password [examplepassword]  <br/> 
            

            c。添加 gmail 帐户。

            例子:

            account Gmail
            tls on 
            tls_certcheck off
            host smtp.gmail.com 
             from [your_gmail_username]@gmail.com 
            auth on
              account default : Gmail 
            

            d。重启 Apache 服务器


            我没有使用 gmail。我使用了我的托管帐户。如果您这样做,请确保 SMTP 设置正确。我的是 mail.abc.com 而不是 smtp.gmail.com。 此代码来自 2 个网站。您需要更改这两个文件。 我让它在运行在 win200sp4 机器上的 Xampp 1.73 上工作。除这两个文件外的所有默认设置。 php.ini 和 sendmail.ini

            【讨论】:

              【解决方案7】:
              THIS IS WHAT YOU SENDMAIL SHOULD LOOK LIKE
              
              
              [sendmail]
              
              ; you must change mail.mydomain.com to your smtp server,
              ; or to IIS's "pickup" directory.  (generally C:\Inetpub\mailroot\Pickup)
              ; emails delivered via IIS's pickup directory cause sendmail to
              ; run quicker, but you won't get error messages back to the calling
              ; application.
              
              smtp_server=smtp.gmail.com
              
              ; smtp port (normally 25)
              
              smtp_port=465
              
              ; SMTPS (SSL) support
              ;   auto = use SSL for port 465, otherwise try to use TLS
              ;   ssl = always use SSL
              ;   tls  = always use TLS
              ;   none = never try to use SSL
              
              smtp_ssl=auto
              
              ; the default domain for this server will be read from the registry
              ; this will be appended to email addresses when one isn't provided
              ; if you want to override the value in the registry, uncomment and modify
              
              ;default_domain=mydomain.com
              
              ; log smtp errors to error.log (defaults to same directory as sendmail.exe)
              ; uncomment to enable logging
              
              error_logfile=error.log
              
              ; create debug log as debug.log (defaults to same directory as sendmail.exe)
              ; uncomment to enable debugging
              
              debug_logfile=debug.log
              
              ; if your smtp server requires authentication, modify the following two lines
              
              auth_username=Your Email Here
              auth_password=Your Password Here
              
              ; if your smtp server uses pop3 before smtp authentication, modify the 
              ; following three lines.  do not enable unless it is required.
              
              pop3_server=
              pop3_username=
              pop3_password=
              
              ; force the sender to always be the following email address
              ; this will only affect the "MAIL FROM" command, it won't modify 
              ; the "From: " header of the message content
              
              force_sender=Your Email Here
              
              ; force the sender to always be the following email address
              ; this will only affect the "RCTP TO" command, it won't modify 
              ; the "To: " header of the message content
              
              force_recipient=
              
              ; sendmail will use your hostname and your default_domain in the ehlo/helo
              ; smtp greeting.  you can manually set the ehlo/helo name if required
              
              hostname=smtp.gmail.com
              
              THIS IS WHAT YOU PHP.INI FILE SHOULD LOOK LIKE
              
              [mail function]
              ; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
              smtp_server=smtp.gmail.com
              smtp_port = 465
              
              ; For Win32 only.
              ; http://php.net/sendmail-from
              ;sendmail_from = postmaster@localhost
              
              ; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:\program filesC:\xampp) fakemail and mailtodisk do not work correctly.
              ; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:\sendmail) and use this for sendmail_path.  
              ; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
              sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
              
              ; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:\xampp\mailoutput folder
              ;sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"
              
              ; Force the addition of the specified parameters to be passed as extra parameters
              ; to the sendmail binary. These parameters will always replace the value of
              ; the 5th parameter to mail(), even in safe mode.
              ;mail.force_extra_parameters =
              
              ; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
              mail.add_x_header=Off
              

              【讨论】:

                【解决方案8】:

                我所要做的就是将“允许不太安全的应用访问您的帐户”切换为开启状态。我想这是创建应用专用密码的替代方法。

                https://support.google.com/accounts/answer/6010255 了解详情

                https://www.google.com/settings/security/lesssecureapps 用于开关

                为了安全起见,在完成后可能值得将其关闭。

                【讨论】:

                  【解决方案9】:

                  使用 Gmail 时还有另一个问题。 Gmail 现在具有安全性,因此您必须生成特定于应用程序的密码 - 您不能使用您拥有的密码进行正常的 Gmail 访问。我通过尝试上面的示例发现了这一点,然后注意到在 sendmail 文件夹中生成了一个错误日志。在错误日志中,我遇到了一条表明这一点的消息。

                  【讨论】:

                  • 我用我的账户试过了,它有效,但只用端口 465
                  【解决方案10】:

                  好的,今天,最佳答案对我不起作用。但是,这样做了:

                  sendmail.ini 中:

                  [sendmail]
                  smtp_server=smtp.gmail.com
                  smtp_port=587
                  error_logfile=error.log
                  debug_logfile=debug.log
                  auth_username=****@gmail.com
                  auth_password=*******
                  force_sender=****@gmail.com
                  

                  php.ini:

                  [mail function]
                  sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
                  

                  基于端口@:http://support.google.com/mail/bin/answer.py?hl=en&answer=13287

                  【讨论】:

                    【解决方案11】:

                    这对我有用希望没有其他人会像我一样烧油来解决这个问题。

                    这是我的 sendmail.ini

                    [sendmail]
                    
                    smtp_server=smtp.gmail.com
                    smtp_port=25
                    error_logfile=error.log
                    debug_logfile=debug.log
                    auth_username=myemail@gmail.com
                    auth_password=yourgmailpassword
                    force_sender=myemail@gmail.com
                    

                    php/php.ini ----基本上注释掉除了sendmail_path & mail.add_x_header之外的所有内容

                    [mail function]
                    ; For Win32 only.
                    ; http://php.net/smtp
                    ;SMTP = localhost
                    ; http://php.net/smtp-port
                    ;smtp_port = 25
                    
                    ; For Win32 only.
                    ; http://php.net/sendmail-from
                    ;sendmail_from = postmaster@localhost
                    
                    ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
                    ; http://php.net/sendmail-path
                    sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
                    
                    ; Force the addition of the specified parameters to be passed as extra parameters
                    ; to the sendmail binary. These parameters will always replace the value of
                    ; the 5th parameter to mail(), even in safe mode.
                    ;mail.force_extra_parameters =
                    
                    ; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
                    mail.add_x_header = Off
                    
                    ; Log all mail() calls including the full path of the script, line #, to address and headers
                    ;mail.log = "C:\xampp\apache\logs\php_mail.log"
                    

                    在我更新了 sendmail 文件后这对我有用(旧的不支持 smtp)

                    • 转到http://glob.com.au/sendmail/ 并获取最新的 sendmail zip 文件
                    • 解压缩到桌面并将文件复制到您的 \xampp\sendmail 文件夹中,替换那里的所有内容。一切!
                    • 现在打开 sendmail.ini 并复制粘贴我上面显示的内容。(先删除该文件中的所有内容或将所有内容注释掉!)
                    • 注意:您不需要为此启动 Mercury 服务器。

                    当我遇到这个问题时,我正在本地主机上进行密码恢复 php。我需要向用户发送他们的密码。 - 你的 php 看起来不错

                    【讨论】:

                    • 这对我来说非常有效。只是添加一个节省时间的注意事项:记住在更改配置文件后重新启动 Apache。
                    • 您说“旧的不支持 smtp”,但我认为您的意思是“旧的不支持 TLS”。
                    • 我还有 2 个注意事项:1) 我必须启用安全性较低的应用程序才能访问我的 Gmail 帐户(转到 Gmail > 帐户 > 安全性); 2) 我必须使用端口 587 而不是 25。
                    • 注意:这也适用于 AMPPS,您只需将 sendmail_path 替换为您安装的 AMPPS 之一。
                    猜你喜欢
                    • 2012-06-16
                    • 2013-12-19
                    • 2013-04-25
                    • 2015-04-23
                    • 2018-09-03
                    • 2012-06-08
                    • 2016-02-05
                    • 2023-02-17
                    • 1970-01-01
                    相关资源
                    最近更新 更多