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

如何解决如何纠正使用codeigniter发送电子邮件的方式

| 嗨,我正在尝试使用codeiginiter邮件类功能发送电子邮件,但是我发现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\'] = \'me@gmail.com\'; // 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(\'me@gmail.com\',\'Me\');
    $this->email->reply_to(\'me@gmail.com\',\'Me\');
    $this->email->to(\'you@yahoo.com\');
    $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: you@yahoo.com
Subject: =?utf-8?Q?testing_my_mail_function_with_CodeIgniter?=
X-Sender: me@gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <4de5a38938720@gmail.com>
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才能发送邮件。它没有使用标准的未加密端口25的方法。 您基本上有两个选择。 1)使用sendmail或您自己的服务器上的邮件来传递消息,或2)使用此处介绍的方法使用SSL通过Google的服务器发送电子邮件。祝您好运,希望对您有所帮助。     ,        您正在尝试通过标准SMTP端口25上的Gmail发送出站邮件。Gmail不接受该端口(或任何端口)上未加密的连接。您必须在SSL上使用端口“ 2”。 您必须将
$config[\'smtp_port\']
更改为
465
,并将
$config[\'smtp_host\']
更改为
\'ssl://smtp.googlemail.com\'
更多信息在这里     ,        您甚至可以使用端口587:
$config[\'smtp_port\'] = \'587\';
和smtp-host为:
$config[\'smtp_host\'] = \'ssl://smtp.gmail.com\';
    ,        我通过在
smtp_host
上包含ssl前缀来解决此问题,方法如下:
$config[\'smtp_host\'] = \'ssl://smtp.gmail.com\';
并确保使用465端口(即Google的smtp端口):
$config[\'smtp_port\'] = \'465\';
否则,默认情况下google会阻止\'低安全性连接\',因此您可以输入自己的google帐户并配置此选项。 允许安全性较低的应用访问帐户 激活此选项,然后重试。希望这可以帮到你!。     ,        1)您的smtp端口必须为
465
。 2)您的smtp主机必须为
ssl://smtp.gmail.com
$config[\'smtp_host\'] = \'ssl://smtp.gmail.com\'; // SMTP Server Address.

$config[\'smtp_port\'] = \'465\'; // SMTP Port.
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-