Home  >  Article  >  php教程  >  通过ci框架mail邮件类发送邮件

通过ci框架mail邮件类发送邮件

WBOY
WBOYOriginal
2016-06-06 19:38:401411browse

通过ci框架mail邮件类发送邮件和利用利用第三方平台发送邮件 无 public function mail(){ $param = array(); $param['to'] = 'qing.chen'; $param['subject'] = '邮件测试-标题'; //$param['tmpl'] = 'email/demo'; $param['content'] = "111"; $this-MailMod

通过ci框架mail邮件类发送邮件和利用利用第三方平台发送邮件
public function mail()
{
    $param = array();
    $param['to'] = 'qing.chen';
    $param['subject'] = '邮件测试-标题';
    //$param['tmpl'] = 'email/demo';
    $param['content'] = "111";
     
    $this->MailModel->sendMail($param);
     
    echo 'sss';
     
}
class MailModel extends CI_Model
{
    /**
     * 生成邮件内容
     * 
     * @param string $templ
     * @param array $data
     * @return string
     * @author http://blog.iwshop.com/

     */
    public function makeBody($tmpl, $data)
    {
        $content = $this->load->view($tmpl, $data, true);
        return $content;
    }
     
  /**
   * 发送邮件
   * 
   * @param array $param
   * @return boolean
   */
  public function sendMail($param)
  {
      // 发件人配置
      if ( empty($param['frommail']))   $param['frommail'] = 'woims';
      if ( empty($param['fromname'])) $param['fromname'] = '运营平台';
      $param['frommail'] = $this->_domain($param['frommail']);
   
      // CI mail 配置
      $this->load->library('email');     
     $config = array();
     $config['charset']  = "UTF-8";  // 编码
     $config['wordwrap'] = TRUE;     // 自动换行
     $config['mailtype'] = 'html';   // 格式 (text/html)
     $config['protocol'] = 'SMTP';   // 邮件协议
     $this->email->initialize($config);
      
     //$param['cc'] = 'barly.li,qingbin.wu';
       
      $this->email->from($param['frommail'], $param['fromname']);
      if ( $param['to'])  $this->email->to($this->_domain($param['to']));
      if ( $param['cc'])  $this->email->cc($this->_domain($param['cc']));
      if ( $param['bcc']) $this->email->bcc($this->_domain($param['bcc']));
       
      //如果存在邮件模板使用模板作为邮件内容 2015-01-08
      $param['content'] = $param['tmpl'] ? $this->makeBody($param['tmpl'], $param['data']) : $param['content'];
       
      $this->email->subject($param['subject']);
      $this->email->message($param['content']);
      $this->email->send();
      return true;
  }
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn