zoukankan      html  css  js  c++  java
  • Codeigniter SMTP 發送email

    原因:

    使用Codeigniter的时候,我们经常需要进行发送邮件进行提醒自己或者通知别人,这时候,我们就可以使用Codeigniter自带的类Email来完成工作。

    介绍:

    通过查看Email.php文件,我们看到Codeigniter可以使用三种protocol来发送邮件:

    [php] view plaincopy
     
    1. var    $protocol        = "mail";    // 分别是mail/sendmail/smtp  

    那我们这里使用的是smtp。

    使用:

    首先要选择email,我这里选择的是google的gmail,gmail一般不会被认为是垃圾邮件,但是gmail的smtp是ssl方式的,所以主机必须要安装ssl才能使用。

    [php] view plaincopy
     
    1. $config['protocol']     = 'smtp';  
    2. $config['smtp_host']    = 'ssl://smtp.gmail.com';  
    3. $config['smtp_user']    = 'youremail@gmail.com';  
    4. $config['smtp_pass']    = 'yourpassword';  
    5. $config['smtp_port']    = '465';  
    6. $config['charset']      = 'utf-8';  
    7. $config['mailtype']     = 'text';  
    8. $config['smtp_timeout'] = '5';  
    9. $config['newline'] = " ";  
    10. $this->load->library ('email'$config);  
    11. $this->email->from ('from@email.com''From email name');  
    12. $this->email->to ('to@email.com''To email name');  
    13. $this->email->bcc ('bcc@email.com');  
    14. $this->email->subject ('Test subject');  
    15. $this->email->message ('The content');  
    16. $this->email->send ();  

    为了查看是否工作,使用如下指令进行Debug:

    [php] view plaincopy
     
    1. echo $this->email->print_debugger();  
    2. exit;  
  • 相关阅读:
    Maven+SpringMVC+Mybatis 开发环境整合
    在子jsp页面中调用父jsp中的function或父jsp调用子页面中的function
    动态库的生成和调用
    怎么下载纯净版系统
    ATL开发COM组件
    链表问题
    内存理解
    静态绑定和动态绑定;位拷贝和值拷贝
    导EXCEL单表单方法
    mfc解决回车键默认关闭窗口的一般方法
  • 原文地址:https://www.cnblogs.com/abinlove/p/3708851.html
Copyright © 2011-2022 走看看