2013-07-18 50 views
-1

我正在做一個使用Codeigniter(移動網站)的項目。我希望用戶收到的郵件,如註冊,忘記密碼,通訊等。目前我在做什麼是這樣的:郵寄服務

function sendEmail($email) { 
     $config = Array(
      'protocol' => 'smtp', 
      'smtp_host' => 'ssl://smtp.googlemail.com', 
      'smtp_port' => '465', 
      'smtp_user' => '[email protected]', 
      'smtp_pass' => 'password', 
      'mailtype' => 'html', 
      'charset' => 'iso-8859-1' 
      ); 
     $this->load->library('email', $config); 
     $this->email->set_newline("\r\n"); 
     $this->email->from('[email protected]', 'user'); 
     $this->email->to($email); 
     $this->email->subject('Thank You for Registering'); 
     $this->email->message('Thank You for Registering .'); 
     if($this->email->send()){ 
      echo "Success"; 
     } 
     else { 
      echo "failed"; 
     } 
    } 

這種運作良好。但是,當你想發送2-3種類型的郵件時,這是做事的正確方法嗎?請幫助我。

回答

0

我建議不要在生產中使用Gmail smtp作爲Web應用程序。而是使用高級(付費)服務,如www.mailgin.com,您也可以使用自己的域名進行發送等。 或者設置您自己的電子郵件服務器。

我也建議使用框架用於發送郵件,例如www.swiftmailer.org

1

我建議創建email.php文件夾./application/config,把你的配置數組中的文件。所以當你改變你的電子郵件設置時,它會反映到整個應用程序中欲瞭解更多詳情,請訪問Email class in codeigniter