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;  
  • 相关阅读:
    C#网络爬虫 WebUtility使用 转义字符 urlCode
    C#遍历文件夹及文件
    ThreadException
    unhandledException
    linq to object
    扩展方法
    反射常规
    字典缓存和泛型缓存
    lock和Monitor(锁对象)
    单例模式
  • 原文地址:https://www.cnblogs.com/abinlove/p/3708851.html
Copyright © 2011-2022 走看看