如何正确使用 codeigniter 发送电子邮件的方式

2024-03-18

嘿伙计,我正在尝试使用 codeigniter 邮件类函数发送电子邮件,但我发现 smtp 协议有问题。我使用gmail smtp协议。 我在本地机器上运行这个。 我正在使用 Xampp 1.7.4 包,并且我尝试过如下设置:

function index()
{

    $config['protocol'] = 'smtp'; // mail, sendmail, or smtp    The mail sending protocol.
    $config['smtp_host'] = 'smtp.gmail.com'; // SMTP Server Address.
    $config['smtp_user'] = '[email protected] /cdn-cgi/l/email-protection'; // SMTP Username.
    $config['smtp_pass'] = '123'; // SMTP Password.
    $config['smtp_port'] = '25'; // SMTP Port.
    $config['smtp_timeout'] = '5'; // SMTP Timeout (in seconds).
    $config['wordwrap'] = TRUE; // TRUE or FALSE (boolean)    Enable word-wrap.
    $config['wrapchars'] = 76; // Character count to wrap at.
    $config['mailtype'] = 'html'; // text or html Type of mail. If you send HTML email you must send it as a complete web page. Make sure you don't have any relative links or relative image paths otherwise they will not work.
    $config['charset'] = 'utf-8'; // Character set (utf-8, iso-8859-1, etc.).
    $config['validate'] = FALSE; // TRUE or FALSE (boolean)    Whether to validate the email address.
    $config['priority'] = 3; // 1, 2, 3, 4, 5    Email Priority. 1 = highest. 5 = lowest. 3 = normal.
    $config['crlf'] = "\r\n"; // "\r\n" or "\n" or "\r" Newline character. (Use "\r\n" to comply with RFC 822).
    $config['newline'] = "\r\n"; // "\r\n" or "\n" or "\r"    Newline character. (Use "\r\n" to comply with RFC 822).
    $config['bcc_batch_mode'] = FALSE; // TRUE or FALSE (boolean)    Enable BCC Batch Mode.
    $config['bcc_batch_size'] = 200; // Number of emails in each BCC batch.

    $this->load->library('email');
    $this->email->initialize($config);


    $this->email->from('[email protected] /cdn-cgi/l/email-protection', 'Me');
    $this->email->reply_to('[email protected] /cdn-cgi/l/email-protection', 'Me');
    $this->email->to('[email protected] /cdn-cgi/l/email-protection');
    $this->email->subject('testing my mail function with CodeIgniter');
    $this->email->message('<html><body>this is the content</body></html>');

    if ( ! $this->email->send()){
        echo 'error! <br />';
        // Generate error
    }
    echo $this->email->print_debugger();

}

我的浏览器中显示以下错误:

error!
220 mx.google.com ESMTP b8sm581192pbj.46

hello: 250-mx.google.com at your service, [118.96.231.25]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250 ENHANCEDSTATUSCODES

Failed to send AUTH LOGIN command. Error: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46

from: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46

The following SMTP error was encountered: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46

to: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46

The following SMTP error was encountered: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46

data: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46

The following SMTP error was encountered: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46
502 5.5.1 Unrecognized command. b8sm581192pbj.46
The following SMTP error was encountered: 502 5.5.1 Unrecognized command. b8sm581192pbj.46
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

User-Agent: CodeIgniter
Date: Wed, 1 Jun 2011 09:27:21 +0700
From: "Me" 
Return-Path: 
Reply-To: "Me" 
To: [email protected] /cdn-cgi/l/email-protection
Subject: =?utf-8?Q?testing_my_mail_function_with_CodeIgniter?=
X-Sender: [email protected] /cdn-cgi/l/email-protection
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <[email protected] /cdn-cgi/l/email-protection>
Mime-Version: 1.0


Content-Type: multipart/alternative; boundary="B_ALT_4de5a38938733"

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

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

this is the content


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

<html><body>this is the content</body></html>

--B_ALT_4de5a38938733--

出于安全原因,Google 的电子邮件服务器需要 SSL 或 TLS http://mail.google.com/support/bin/answer.py?answer=13287为了发送邮件。它不使用标准的未加密端口 25 方法来执行此操作。

你基本上有两个选择。 1)使用sendmail或您自己的服务器上的mail来传递消息,或2)使用该方法此处描述 https://ellislab.com/forums/viewthread/84689/使用 SSL 通过 Google 服务器发送电子邮件。祝你好运,我希望这会有所帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何正确使用 codeigniter 发送电子邮件的方式 的相关文章

  • Laravel $request->file() 返回 null

    尝试在后端使用 Laravel 上传文件时遇到问题 Issue Laravel request gt file 方法返回 null Setup 我使用以下方法构建了一个 AJAX 请求超级代理人 https github com visio
  • php 数组中出现意外的 json 输出结构

    我正在尝试转换动态数据 如何从 PHP 获取此 JSON JSON 122240cb 253c 4046 adcd ae81266709a6 item 0 3 这就是我所做的 但它不起作用 PHP json array 122240cb 2
  • 免费 PHP 登录库 [关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • Yii2 - 错误请求 (#400) |前端和后端cookie

    仅当我打开时才会出现此问题frontend and backend在相同的browser 设想 与后端交互 gt 切换选项卡 gt 与前端交互 gt 切换选项卡返回 gt 与后端交互 gt 错误请求 400 Cookie 后端 identi
  • 您的要求无法解析为 laravel 的一组可安装软件包

    我使用 5 7v Laravel 和 7 2 1v PHP 和 Composer 最新版本 但是当我想创建新项目时出现这些错误 Your requirements could not be resolved to an installabl
  • CakePHP 视图包括其他视图

    我有一个 CakePHP 应用程序 在某些时候会显示带有产品媒体 图片或视频 的视图 我想知道是否有某种方式可以包含另一个威胁视频或威胁图片的视图 具体取决于标志 我想将这些 小视图 用于其他几个目的 所以它应该 像 蛋糕组件一样 以便重用
  • 如何在 JavaScript 中创建服务器端进度指示器?

    我想在我的网站中创建一个部分 用户可以在其中进行一些简单的操作update纽扣 这些中的每一个update按钮将发送到服务器 并在幕后进行长时间的处理 当服务器处理数据时 我希望用户有某种进度指示器 例如进度条或文本百分比 我使用 jQue
  • 如何将表中不存在但原始SQL中存在的实体字段设置为别名?

    假设我们有一个这样的查询 SELECT CUSTOM EXPRESSION as virtualfield FROM users 用户的实体本身具有 虚拟字段 但映射注释没有 因为表没有该字段 假设它作为原始 SQL 执行 我们如何使用上面
  • 使用值填充的 Symfony2 自定义字段类型

    这是先前问题的后续问题Symfony2 自定义表单类型或扩展 https stackoverflow com questions 24079288 symfony2 custom form type or extension 我正在尝试为订
  • docker 中的 php Curl 冲突 CURLOPT_FILE 和 CURLOPT_RETURNTRANSFER

    当我使用curl时CURLOPT FILE and CURLOPT RETURNTRANSFER选项 文件为空 没有任何curl错误 fp fopen saveTo w ch curl init fileUrl curl setopt ch
  • 在 PHP 字符串中格式化 MySQL 代码

    是否有任何程序 IDE 可以在 PHP 字符串中格式化 MySQL 代码 例如 我使用 PHPStorm IDE 但它无法做到这一点 它对 PHP 和 MYSQL 执行此操作 但不适用于 php 字符串内的 MYSQL 我已准备好使用新的
  • 使用 PHP 从 Mongo 解码 JSON

    我已经看过这个线程 PHP 解码嵌套 JSON https stackoverflow com questions 3555335 php decode nested json并没有设法用它来解决我的问题 我目前正在从 Mongo 获取 J
  • 如何使用更新资源控制器 laravel 4?

    我有带有索引 编辑 更新方法的客户控制器 Route resource customer CustomerController 控制器方法更新 public function update id echo id 我的 HTML 表单
  • 从 Laravel 4 输入生成新数组

    我使用 Input all 从动态生成的表单中获取一些输入 我使用 jQuery 来允许用户添加字段 字段名称为 first names last names 和 emails input 变量现在看起来像这样 array size 4 t
  • 使用会话 php 创建 cookie?

    我使用会话来登录我网站中的用户 问题是 我想让用户remember密码 因此关闭 打开浏览器后他们不需要再次登录 我需要使用 cookie 和 session 来实现它吗 my code user POST user pass POST p
  • Laravel 搜索关系

    我有两个相关的模型 我正在尝试在产品中进行搜索 并且仅显示实际搜索结果 而不是找到该产品的类别的所有产品 我不想搜索任何类别 因为无论搜索什么或找到什么 类别都会始终显示 Example I have the following categ
  • 矩形超出边界是什么意思

    PPB Graphics2D PaintImageData 矩形超出界限是什么意思 我几乎在我检查的每一段代码中都看到了它 最新的代码是 define my consumer key define my consumer secret oa
  • 如何在 PHP 5.6 中通过 php.ini 设置“verify_peer_name=false”SSL 上下文选项

    案例 我想打开 SSL 连接localhost而 SSL 证书是 FQDN 的问题 问题 没有进行特殊处理就行 下面的程序失败并显示以下消息 PHP Warning stream socket enable crypto Peer cert
  • 发送用户注册密码,django-allauth

    我在 django 应用程序上使用 django alluth 进行身份验证 注册 我需要创建一个自定义注册表单 其中只有一个字段 电子邮件 密码将在服务器上生成 这是我创建的表格 from django import forms from
  • 如何从日期中查找该月的最后一天?

    如何在 PHP 中获取该月的最后一天 Given a date 2009 11 23 我要2009 11 30 并给出 a date 2009 12 23 我要2009年12月31日 t返回给定日期所在月份的天数 请参阅的文档date ht

随机推荐