CI框架 email类发送邮件

下表为发送邮件时所有可用的参数。

参数 默认值 选项 描述
useragent CodeIgniter None 用户代理(user agent)
protocol mail mail, sendmail, or smtp 邮件发送协议
mailpath /usr/sbin/sendmail None 服务器上 Sendmail 的实际路径
smtp_host No Default None SMTP 服务器地址
smtp_user No Default None SMTP 用户名
smtp_pass No Default None SMTP 密码
smtp_port 25 None SMTP 端口
smtp_timeout 5 None SMTP 超时时间(单位:秒)
smtp_keepalive FALSE TRUE or FALSE (boolean) 是否启用 SMTP 持久连接
smtp_crypto No Default tls or ssl SMTP 加密方式
wordwrap TRUE TRUE or FALSE (boolean) 是否启用自动换行
wrapchars 76   自动换行时每行的最大字符数
mailtype text text or html 邮件类型。如果发送的是 HTML 邮件,必须是一个完整的网页, 确保网页中没有使用相对路径的链接和图片地址,它们在邮件中不能正确显示。
charset $config['charset']   字符集(utf-8, iso-8859-1 等)
validate FALSE TRUE or FALSE (boolean) 是否验证邮件地址
priority 3 1, 2, 3, 4, 5 Email 优先级(1 = 最高. 5 = 最低. 3 = 正常)
crlf \n "\r\n" or "\n" or "\r" 换行符(使用 "rn" 以遵守 RFC 822)
newline \n "\r\n" or "\n" or "\r" 换行符(使用 "rn" 以遵守 RFC 822)
bcc_batch_mode FALSE TRUE or FALSE (boolean) 是否启用密送批处理模式(BCC Batch Mode)
bcc_batch_size 200 None 使用密送批处理时每一批邮件的数量
dsn FALSE TRUE or FALSE (boolean) 是否启用服务器提示消息



1
 public function email(){
2
        $this->load->library('email');
3
4
        $config['protocol'] = 'smtp';
5
        $config['smtp_host'] = 'smtp.163.com';
6
        $config['smtp_user'] = 'helloworld_assad@163.com';
7
        $config['smtp_pass'] = "*********";           //填写邮箱的 SMTP/POP 等的授权码
8
        $config['smtp_port'] = 25;
9
        $config['charset'] = 'utf-8';
10
        $config['smtp_timeout'] = 30;
11
        $config['mailtype'] = 'text';
12
        $config['validate'] = TRUE;
13
        $config['wordwrap'] = TRUE;
14
        $config['crlf'] = '\r\n';
15
        $config['newline'] = '\r\n';
16
        $this->email->initialize($config);
17
        $this->email->from('helloworld_assad@163.com','assad');
18
        $this->email->to('yulinying_1994@outlook.com');
19
        $this->email->subject('Email Test');
20
        $this->email->message("This is a eamil just testing the CI class");
21
22
23
        if($this->email->send()){
24
            echo 'the email is sent';
25
        }else{
26
            echo 'email sent fail';
27
        }
28
        
29
    }


不同的邮件提供商提供的protocol可能不同,具体要登录相应邮箱进行设置;

邮件message中取消自动换行:
1
{unwrap}http://example.com/a_long_link_that_should_not_be_wrapped.html{/unwrap}


异常报错可以使用以下生成调试报告
1
echo $this->email->print_debugger();





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值