CodeIgniter配置email類使用騰訊企業郵箱

$msg = "郵件內容";
$email = "test@qq.com";
$config = array(
        'crlf'          => "\r\n",
        'newline'       => "\r\n",
        'charset'       => 'utf-8',
        'protocol'      => 'smtp',
        'mailtype'      => 'html',
        'smtp_host'     => 'smtp.exmail.qq.com',
        'smtp_port'     => '25',
        'smtp_user'     => 'xxx@domain.com',
        'smtp_pass'     => 'emailpwd'
);

$this->load->library('email', $config);

$this->email->from('xxx@domain.com', '系統郵件');
$this->email->to($email);

$this->email->subject('系統郵件');
$this->email->message($msg);

if($this->email->send()){ 
    $res = "ok";
}else{
    $res = "faild";
}

另外要判斷下發送的結果,若是發送成功會返回TRUE。
以前配置寫錯了,一直把smtp_port寫成了465,致使各類發送失敗,還好一直沒用上這個功能。。
寫下來記一下。html

相關文章
相關標籤/搜索