2013-11-25 174 views
0

我對codeigniter很陌生..我想使用CI的電子郵件庫從我的服務器發送電子郵件。 我做了一個代碼,它在本地主機上完美工作,但沒有在我的服務器上工作。codeigniter從真實服務器發送電子郵件失敗

這是我在控制器功能:

public function send_task(){ 
    $config = Array(
     'protocol' => "smtp", //when you use gmail 
     'smtp_host' => "smtp.googlemail.com", 
     'smtp_port' => 465, 
     'smtp_user' => "[email protected]", 
     'smtp_pass' => "******", 
    ); 

    $config['crlf'] = '\r\n'; 
    $config['newline'] = '\r\n'; 
     $this->load->library('email', $config); 

     $this->email->from('[email protected]', 'Media Club - Sales'); 
     $this->email->to('[email protected]'); 
     $this->email->subject('Sales System New Task'); 
     $this->email->message('Hi There'); 

     if($this->email->send()) { 
      echo 'Email sent.'; 
     }else { 
      show_error($this->email->print_debugger()); 
     }  
    } 

和錯誤是: enter image description here

我不知道什麼是錯在這個配置做。所以我真的需要幫助。 感謝提前:) :)

回答

1

嘗試用這個,可以幫助你

$config = Array(  
      'protocol' => 'smtp', 
      'smtp_host' => 'ssl://smtp.googlemail.com', 
      'smtp_port' => 465, 
      'smtp_user' => '<your username>@gmail.com', 
      'smtp_pass' => '<your password>', 
      'smtp_timeout' => '4', 
      'mailtype' => 'text', 
      'charset' => 'iso-8859-1' 
     ); 

     $this->load->library('email', $config); 
     $this->email->set_newline("\r\n") 

你在你的config文件夾中的文件email.php。也許你的配置有問題,請檢查一下。

+0

不工作..我認爲問題是與我的服務器..我的意思是我應該在服務器上的SMTP設置的任何配置? – Fareed

+0

您可以將smtp_port更改爲25並再次檢查。這可能有幫助 –

+0

好的,我發現有什麼問題..我應該讓我的Gmail接受使用diffirent服務器登錄 – Fareed

1
function send_email(){ 
     $this->emailformat(); 
}  

function emailformat(){ 
       $config['protocol'] = 'smtp'; // mail, sendmail, or smtp The mail sending protocol. 
       $config['smtp_host'] = '10.10.20.20'; // SMTP Server Address. 
       $config['smtp_user'] = '[email protected]'; // SMTP Username. 
       $config['smtp_pass'] = '12345'; // SMTP Password. 
       $config['smtp_port'] = '25'; // SMTP Port. 
       $config['smtp_timeout'] = '5'; // SMTP Timeout (in seconds). 
       $config['wordwrap'] = TRUE; // TRUE or FALSE (boolean) Enable word-wrap. 
       $config['wrapchars'] = 76; // Character count to wrap at. 
       $config['mailtype'] = 'html'; // text or html Type of mail. If you send HTML email you must send it as a complete web page. Make sure you don't have any relative links or relative image paths otherwise they will not work. 
       $config['charset'] = 'utf-8'; // Character set (utf-8, iso-8859-1, etc.). 
       $config['validate'] = FALSE; // TRUE or FALSE (boolean) Whether to validate the email address. 
       $config['priority'] = 3; // 1, 2, 3, 4, 5 Email Priority. 1 = highest. 5 = lowest. 3 = normal. 
       $config['crlf'] = "\r\n"; // "\r\n" or "\n" or "\r" Newline character. (Use "\r\n" to comply with RFC 822). 
       $config['newline'] = "\r\n"; // "\r\n" or "\n" or "\r" Newline character. (Use "\r\n" to comply with RFC 822). 
       $config['bcc_batch_mode'] = FALSE; // TRUE or FALSE (boolean) Enable BCC Batch Mode. 
       $config['bcc_batch_size'] = 200; // Number of emails in each BCC batch. 

        $this->load->library('email'); 
        $this->email->initialize($config); 
        $this->email->from('[email protected]', 'Robot'); 
        $this->email->to('[email protected]'); 
        $this->email->subject('subject'); 
        $this->email->message('<html><body>This Message is to notify you that '.$c_id.' contract will expire in' !</body></html>'); 
        $this->email->send(); 
     } 
相關問題