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

Email类的使用问题

[复制链接]
发表于 2015-3-12 18:07:08 | 显示全部楼层 |阅读模式
1 需不需设置php.ini?在winodws下和linux下设置的内容有什么差别?不同的PHP版本有什么差别?我看了php.ini里面和邮件有关的设置如下:
PHP复制代码
 
[mail function]
; For Win32 only.
; [url]http://php.net/smtp[/url]
SMTP = smtp.exmail.qq.com
; [url]http://php.net/smtp-port[/url]
smtp_port = 465
 
; For Win32 only.
; [url]http://php.net/sendmail-from[/url]
sendmail_from = [email]whb@blb.com.cn[/email]
 
; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; [url]http://php.net/sendmail-path[/url]
 
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =
 
; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = On
sendmail_path="C:\phpStudy\tools\sendmail\sendmail.exe -t"
 
; The path to a log file that will log all mail() calls. Log entries include
; the full path of the script, line number, To address and headers.
;mail.log =
; Log mail to syslog (Event Log on NT, not valid in Windows 95).
;mail.log = syslog
 
 
复制代码

这里面的设置和Email类里面的设置有一样的,例如smtp_port、sendmail_from、SMTP在Email类中也可以通过
PHP复制代码
 
 $config['smtp_host'] = "smtp.exmail.qq.com";
$config['smtp_user']  = "whb@blb.com.cn";
 
$config['smtp_port'] = 465;
 
复制代码

设置。这两个设置内容都是一样的。是不是都需要设置。
另外我还看了gocart系统里面是怎么使用的。
结果如下:
PHP复制代码
 
                                $this->load->library('email');
                                $config['mailtype'] = 'html';
                                $this->email->initialize($config);
                                $this->email->from($this->config->item('email'));
                                $this->email->to($save['to_email']);
                                $this->email->subject($row['subject']);
                                $this->email->message($row['content']);
                                $this->email->send();
 
 
复制代码

在它的config文件夹下面没有看到email.php这个配置文件。

我在控制器中发送邮件。代码使用的是文档里面的
PHP复制代码
 
        public function mail()
        {
                $this->load->library('email');
                $this->email->from('whb@blb.com.cn', '小溪-FM');
                $this->email->to('angel836@126.com');
                $this->email->subject('Email Test');
                $this->email->message('Testing the email class.');
                $this->email->send();
                echo $this->email->print_debugger();
        }
 
 
复制代码


 楼主| 发表于 2015-3-12 18:30:22 | 显示全部楼层
我使用126的邮箱发送成功了。
之前的疑问也解答了。
不需要设置php.ini文件。
我的设置如下:
PHP复制代码
 
        public function mail()
        {
                $config['protocol']     = 'smtp';
                $config['smtp_host']    = 'smtp.126.com';
                $config['smtp_user']    = 'angel836@126.com';
                $config['smtp_pass']    = '********';
                $config['smtp_port']    = '25';
                $config['charset']      = 'utf-8';
                $config['mailtype']     = 'text';
                $config['smtp_timeout'] = '5';
                $config['newline']      = "\r\n";
                 
                $this->load->library ('email', $config);
                $this->email->from ('angel836@126.com', 'dolphin');
                $this->email->to ('416509859@qq.com', 'xiaoxi');
                $this->email->subject ('Test subject');
                $this->email->message ('The content');
                $this->email->send ();
 
                // echo $this->email->print_debugger();
        }
 
 
复制代码

本版积分规则