从本地服务器发送电子邮件时出错

Error sending email from local server

我正在尝试使用我的 gmail 帐户从我的本地 wamp 服务器(os 是 windows 10)在 codeigniter 3 中测试一个简单的联系表单。我以前做过很多次,但现在我得到了一个错误。我已经阅读了有关该主题的所有 Stack 线程,但它们只是告诉我做我已经在做的事情,但它不起作用。我联系了 Google,但他们也告诉我做我已经在做的事情。

我的控制器是这样设置的:

        $config = array(
            'protocol'=>'smtp',
            'smtp_host'=>'ssl://smtp.gmail.com',
            'smtp_port'=>465,
            'smtp_user'=>'username@gmail.com',
            'smtp_pass'=>'password',
            'mailtype'=>'text',
            'charset'=>'iso-8859-1',
            'smtp_timeout'=>'30',
            'crlf'=>'r\n',
            'newline'=>'r\n',
            'wordwrap'=>TRUE
        );
        $this->load->library('email',$config);
我相信

php.ini 配置正确。我在我的 Gmail 帐户中启用了 'Allow less secure apps',并且关闭了两步验证。但我仍然收到此错误:

220 smtp.gmail.com ESMTP b36sm5736977edd.67 - gsmtp

hello: 250-smtp.gmail.com at your service, [86.180.98.185]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8

Failed to authenticate password. Error: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials b36sm5736977edd.67 - gsmtp
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

User-Agent: CodeIgniter
Date: Thu, 9 Nov 2017 10:22:00 +0000
From: "Mike Heath" <msheath@btinternet.com>
Return-Path: <msheath@btinternet.com>
To: mike24heath@gmail.com
Subject: =?ISO-8859-1?Q?=43=6F=6E=74=61=63=74=20=4D=65=73=73=61=67=65?=
Reply-To: <msheath@btinternet.com>
X-Sender: msheath@btinternet.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5a042c4818341@btinternet.com>
Mime-Version: 1.0


Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit

我确信我的 username/password 是正确的,因为我可以使用它们登录 gmail。 possibly 可能出了什么问题?感谢任何想法。

我刚刚发现了测试邮件服务器工具,它是我所有电子邮件测试问题的完整答案。忘记 Sendmail、PHPMailer、Gmail 等 http://www.toolheap.com/test-mail-server-tool/