2017-01-23 33 views
0

我是codeigniter中的新手我想使用codeigniter電子郵件類發送電子郵件,但我是得到錯誤的fsockopen():無法連接到smtp.googlemail.com:465(連接超時)我試圖解決這個問題,但沒有運氣獲取錯誤fsockopen():無法連接到smtp.googlemail.com:465(連接超時),同時使用codeigniter電子郵件類發送電子郵件

public function signup() 
{ 
    $this->form_validation->set_rules('email','Email','required|valid_email|is_unique[fbadmin.email]'); 
    $this->form_validation->set_error_delimiters("<p class='text-danger'>","</p>"); 
    if($this->form_validation->run()==TRUE) 
    { 
     $data= $this->input->post(); 
     unset($data['submit']); 
     //print_r($data);exit; 
     $this->load->model('Fbadminmodel'); 
     if($this->Fbadminmodel->signup($data)) 
     { 
      //$this->load->library('email'); 
      $config = array(
       'protocol' =>'smtp', 
       'smtp_host' =>'smtp.googlemail.com', 
       'smtp_port' =>'465', 
       'smtp_user' =>'[email protected]', 
       'smtp_pass' =>'password', 
       'mail_type' =>'html', 
       'charset' =>'utf-8' 
       ); 
      //$this->email->initialize($config); 
      $this->load->library('email', $config); 
      $this->email->from('[email protected]','Anuj Kumar'); 
      $this->email->to($data); 
      $this->email->message('www.haiviral.com'); 
      $this->email->set_newline("\r\n"); 

      if($this->email->send()) 
      { 
       //$this->session->set_flashdata('feedback','Succefully Registred. Please verify your email'); 
       echo "mail send"; 
      } 
      else 
      { 
       show_error($this->email->print_debugger()); 
      } 
     } 
     else 
     { 
      $this->load->view('fbadmin'); 
      $this->session->set_flashdata('feedback','Registration Failed'); 
     } 
     //$this->session->flashdata('flash','Email Sent'); 
     $this->load->view('fbadmin'); 
    } 
    else 
    { 
     echo validation_errors(); 
     $this->load->view('fbadmin'); 
    } 
} 
+0

確保延長=在你的php.ini和 ' 'smtp_host'=>「啓用SSL php_openssl.dll:// smtp.googlemail.com'',通過您的文章作爲int value – webDev

+0

php_openssl.dll已經打開 –

+0

make''smtp_host'=>'ssl:// smtp.googlemail.com'',以int的形式傳遞你的帖子 – webDev

回答

0

有幾件事情,可能是錯的。我會做的第一件事就是設置你的smtp_timeout設置:

$config = array(
    'smtp_timeout'=>'30', //<-- add this 
    'protocol' =>'smtp', 
    'smtp_host' =>'smtp.googlemail.com', 
    'smtp_port' =>'465', 
    'smtp_user' =>'[email protected]', 
    'smtp_pass' =>'password', 
    'mail_type' =>'html', 
    'charset' =>'utf-8' 
); 

接下來我會檢查的是你的主機可以訪問端口465:

$fp = fsockopen("smtp.gmail.com", 465, $errno, $errstr, 10); 
if (!$fp) 
    echo "smtp.gmail.com 465 - $errstr ($errno)<br>\n"; 

如果仍然不工作,我會嘗試禁用Gmail的兩步驗證。

+0

'smtp_timeout'=>'7'已經在電子郵件類文件中設置,但得到同樣的錯誤@dave –

0

添加SSL

$emailConfig = [ 
     'protocol' => 'smtp', 
     'smtp_host' => 'ssl://smtp.googlemail.com', 
     'smtp_port' => 465, 
     'smtp_user' => '[email protected]', 
     'smtp_pass' => 'xxx', 
     'mailtype' => 'html', 
     'charset' => 'iso-8859-1' 
    ]; 
相關問題