php - CodeIgniter 发送 SMTP Gmail

标签 php codeigniter email smtp gmail

嘿伙计们,我正在尝试为我正在开发的这个论坛创建一个重置密码......无论如何,我遵循了一堆指南并尝试了您将看到的许多版本,这是错误最少的一个....我仍然无法弄清楚出了什么问题,我需要你的帮助。

class CI_Email {  //in library email.php

var $useragent      = "CodeIgniter";
var $mailpath       = "/usr/sbin/msmtp";    // Sendmail path
var $protocol       = "smtp";   // mail/sendmail/smtp
var $smtp_host      = "smtp.googlemail.com";        // SMTP Server.
var $smtp_user      = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f19c889c90989db1969c90989ddf929e9c" rel="noreferrer noopener nofollow">[email protected]</a>";       // SMTP Username
var $smtp_pass      = "mypass";     // SMTP Password
var $smtp_port      = "465";        // SMTP Port
var $smtp_timeout   = 5;        // SMTP Timeout in seconds
var $smtp_crypto    = "";       // SMTP Encryption. Can be null, tls or ssl.
var $mailtype       = "html";   // text/html  Defines email formatting
var $charset        = "utf-8";  // Default char set: iso-8859-1 or us-ascii

这就是结果:

hello: 
The following SMTP error was encountered: 
Failed to send AUTH LOGIN command. Error: 
from: 
The following SMTP error was encountered: 
to: 
The following SMTP error was encountered: 
data: 
The following SMTP error was encountered: 

The following SMTP error was encountered: Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method. Content-Type: multipart/alternative; boundary="B_ALT_51cd96f2daf24"

This is a multi-part message in MIME format. Your email application may not support this format.

--B_ALT_51cd96f2daf24 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit

My text here...

--B_ALT_51cd96f2daf24 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

I also tried a lot of other config i found online such as:

    var $mailpath      = "/usr/sbin/sendmail";    // Sendmail path 
    var $smtp_host     = "ssl://smtp.googlemail.com";        // SMTP Server.

或者:

    var $mailpath      = "/usr/sbin/sendmail";    // Sendmail path
    var $smtp_host     = "ssl://smtp.gmail.com";        // SMTP Server.

通过 smtp_host 中的 SSL 协议(protocol),我得到了一个包含无数错误的无尽屏幕。

最佳答案

我使用测试 Gmail 帐户进行非生产 CodeIgniter 电子邮件测试,但当我部署到生产服务器时,我使用 ENVIRONMENT 常量来检测正确的邮件连接设置。

对于 Gmail,我发现这些配置设置(我已将其放入 /application/config/email.php 中)工作正常:

    $config = Array(
      'protocol' => 'smtp',
      'smtp_host' => 'ssl://smtp.googlemail.com',
      'smtp_port' => 465,
      'smtp_user' => '<test-account-name>@gmail.com',
      'smtp_pass' => '<test-account-password>',
    );

您的电子邮件很可能会被收件人的电子邮件标记为垃圾邮件,直到他们将您的发件人列入白名单。

FWIW,不要编辑核心 CodeIgniter 文件,您可以通过多种不同的方式提供连接详细信息。

关于php - CodeIgniter 发送 SMTP Gmail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17366680/

相关文章:

mysql - 获取过去两个月的记录,不包括今天的记录列表

php - 在数据库中获取的数据旁边对表进行编号

azure - 通过 smtp 从 azure 中安装为 IaaS 的服务器发送电子邮件

php - 无法连接mysql(忘记密码)

javascript - 在 Ajax 成功函数中没有得到响应

php - 样式表不适用于 Codeigniter

html - 无法让图像在移动 View 中堆叠

javascript - 在运行时更改表单标签文本

php - grocery-crud add_action如何使用pk?

python - 如何使用 python 和 smtplib 阅读电子邮件