用户
 找回密码
 入住 CI 中国社区
搜索
查看: 6607|回复: 7
收起左侧

[已解决] 关于利用CI的Email类SMTP模式的问题

[复制链接]
发表于 2009-4-18 01:33:18 | 显示全部楼层 |阅读模式
如果在使用SMTP方式发送邮件,并且需要认证的用户名和密码是在php中动态获取的,CI的Email类存在严重的BUG,以至于无法发送邮件;

使用方法如下:
$this->load->library('email');
$config['protocol'] = 'smtp';      
$config['smtp_host'] = 'smtp.126.com';     
$config['smtp_user'] =[email=]'wangmao2002@126.com'[/email];
$config['smtp_pass'] = 'xxx';   
$config['smtp_port'] = 25;  
$config['smtp_timeout'] = 30;                        
$config['charset'] = 'gbk';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->email->from('wangmao2002@126.com';, 'email test');
$this->email->to([email=]'wangmao2002@126.com'[/email]);
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();

使用方法本身没有问题,问题主要存在于CI_Email函数中的语句:
$this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE;

实际运行过程中,$this->_smtp_auth为FALSE,因为这个时候$this->smtp_user和$this->smtp_pass还没有赋值,因此导致后面连上服务器后,无法正常验证用户名和密码;

最简单的办法,就是将这条语句拷贝到initialize函数的最后进行赋值,这样就可以解决认证邮件服务器的认证问题。

评分

参与人数 1威望 +3 收起 理由
Hex + 3 感谢报告 BUG

查看全部评分

发表于 2009-4-18 10:00:48 | 显示全部楼层
确实是个 BUG,官方 BUG 列表中早已有此 BUG 了。
也就是说,必须以
PHP复制代码
$config['protocol']    = 'smtp';
$config['smtp_port']   =  25;
$config['smtp_host']   = 'mail.test.com';
$config['smtp_user']   = 'test@test.com';
$config['smtp_pass']   = 'somepassword';
$this->load->library('email', $config);
复制代码

这样传递才能正确执行,或者加一个
PHP复制代码
$config['_smtp_auth']   = TRUE;
复制代码


等待官方在新版的 CI 中修复此问题吧,不过貌似这个问题是 08 年提交的 -_-
发表于 2009-4-18 10:26:00 | 显示全部楼层
如果你使用自己的smtp服务器,可以避开此问题
 楼主| 发表于 2009-4-18 19:06:03 | 显示全部楼层
多谢管理员,看来我不能只在中文论坛里面搜索了,还得去官方网站搜索一下

管理员提供的方法,如果早点看到的话,就不用那么费劲调试了
发表于 2011-6-1 11:34:48 | 显示全部楼层
要SSL验证的服务器最好加上个SSL前缀
发表于 2011-6-23 14:29:07 | 显示全部楼层
为什么我现在用smtp发email老是报错啊啊  
220 163.com Anti-spam GT for Coremail System (163com[20101010])

hello: 250-mail
250-PIPELINING
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UFHhonmUCa0xDrUUUUj
250-STARTTLS
250 8BITMIME

Failed to authenticate password. Error: 550 用户被锁定

from: 553 Requested action not taken: Local user only,smtp3,DdGowKArOgYR2wJOMqFhAA--.1521S2 1308810002

The following SMTP error was encountered: 553 Requested action not taken: Local user only,smtp3,DdGowKArOgYR2wJOMqFhAA--.1521S2 1308810002

to: 503 bad sequence of commands

The following SMTP error was encountered: 503 bad sequence of commands

data: 503 bad sequence of commands

The following SMTP error was encountered: 503 bad sequence of commands
502 Error: command not implemented
The following SMTP error was encountered: 502 Error: command not implemented
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

User-Agent: CodeIgniter
Date: Thu, 23 Jun 2011 14:18:33 +0800
To: 13436569382@139.com
From:
Return-Path:
Subject: =?utf-8?Q?Here_is_your_info_name?=
Reply-To: "luxz@snailcity.com.cn"
X-Sender: luxz@snailcity.com.cn
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <4e02dab93dc57@snailcity.com.cn>
Mime-Version: 1.0


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

Hi name Here is the info you requested.2011-06-23 14:18:33

发表于 2011-6-25 10:00:31 | 显示全部楼层
挺好
发表于 2012-9-21 17:07:22 | 显示全部楼层
蒙娜丽莎的眼泪 发表于 2011-6-23 14:29
**** 作者被禁止或删除 内容自动屏蔽 ****

因为国内安全网络太强大,可能被拦截了,中国特色

再就是 可能是自己给自己发信 导致的

你换个别的账号发一下试试

本版积分规则