2013-07-22 95 views
0

我是初學者到笨,我想從笨發送電子郵件到Gmail,代碼如下圖所示,在電子郵件笨:發送電子郵件時出錯

電子郵件配置。控制器

 $config = array(
      'protocol' => 'smtp', 
      'smtp_host' => 'ssl://smtp.google.email.com', 
      'smtp_port' => '465', 
      'smtp_user' => '[email protected]', 
      'smtp_pass' => '*****' 
      ); 

然後我加載庫

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

然後我所需要的數據是過時從,到,密碼,主題和消息的電子郵件庫中,

 $this->email->from('[email protected]'); 
     $this->email->to('[email protected]'); 
     $this->email->subject('this is testing email'); 
     $this->email->message('It is working'); 

最後我檢查我的電子郵件是否通過使用休閒條件發送或不發送

 if($this->email->send()==true){ 

      echo "your mail was sent"; 
     } 
     else{ 
      show_error($this->email->print_debugger()); 
     } 
+1

那麼你有什麼?我的意思是錯誤信息? –

+0

請參考這裏的答案 http://stackoverflow.com/questions/18855016/unable-to-send-email –

回答

2

嘗試從本地主機

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

$config['protocol'] = 'smtp'; 
$config['smtp_host'] = 'ssl://smtp.googlemail.com'; 
$config['smtp_port'] = 465; 
$config['smtp_user'] = 'Your email address'; 
$config['smtp_pass'] = 'Your Password'; 

$this->email->initialize($config); 
if($this->email->send()==true){ 

    echo "your mail was sent"; 
} 
else{ 
    show_error($this->email->print_debugger()); 
} 

如果您發送的郵件比你可以用這個,但如果您正在發送從服務器比您不需要使用此SMTP配置

1

您輸入的服務器URL錯誤。它應該是:

SSL://smtp.googlemail.com