2012-05-14 58 views
4

我正在學習使用gmail發送郵件的教程,但是我得到的是一個只是掛起的頁面,甚至沒有加載錯誤。我使用MAMP,這可能是它不工作的原因。通過gmail發送郵件到CodeIgniter

class Email extends CI_Controller{ 

    public function __construct() 
    { 
     parent::__construct(); 

    } 

    function index(){ 

     $config = Array(
      'protocol' => 'smtp', 
      'smtp_host' => 'ssl://smtp.googlemail.com', 
      'smtp_port' => 465, 
      'smtp_user' => 'email', 
      'smtp_pass' => 'pass' 
     ); 

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

     $this->email->set_newline("/r/n"); 
     $this->email->from('email', 'George'); 
     $this->email->to('email'); 
     $this->email->subject('hey this is an email'); 
     $this->email->message('this is the content of the email'); 

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

       echo 'Your message was sent'; 

     }else{ 

      show_error($this->email->print_debugger()); 

     } 

    } 



} 

回答

7
在php.ini文件中取消註釋延長= php_openssl.dll

$config = Array(
      'protocol' => 'smtp', 
      'smtp_host' => 'ssl://smtp.googlemail.com', 
      'smtp_port' => '465', 
      'smtp_user' => '[email protected]', 
      'smtp_pass' => 'password', 
      'mailtype' => 'html', 
      'starttls' => true, 
      'newline' => "\r\n" 
     ); 

    $this->load->library('email', config); 
    $this->email->from('[email protected]', 'George'); 
    $this->email->to('[email protected]'); 
    $this->email->subject('hey this is an email'); 
    $this->email->message('this is the content of the email'); 
    $this->email->send(); 
    echo $this->email->print_debugger(); 

希望

這將工作

+1

我沒有在我的php.ini這一行,但是你提供的代碼似乎工作。我想我需要添加starttls參數。 – Adam

+0

試過這個,它工作。縮小範圍,在我的電子郵件配置中添加'$ config ['newline'] =「\ r \ n」'爲我解決了這個問題。 –

0

線造成的問題是:

$this->email->set_newline("/r/n"); 

刪除它,並嘗試發送郵件。

+0

不,它仍然掛起。有什麼我需要在Gmail中設置? – Adam

+0

你在Gmail中啓用了遠程SMTP嗎? – gorelative

+0

是啓用pop和imap。同時,之間有什麼smtp.gmail.com和SSL的區別://smtp.googlemail.com – Adam

0

我只是做了這個成功的自己,但通過配置發送的所有值/ email.php代替。這部分應該不重要。

基本上你是想通過@gmail帳戶或你自己的域名發送?如果你試圖去通過自己的域名,您需要將DNS更改有關谷歌設置:

Create MX Records

-1

通過使用標準的SMTP端口,並確保使用下面的配置,工程發佈開始:

功能指數(){

$配置=陣列( '協議'=> 'SMTP', 'smtp_host'=> 'smtp.googlemail.com', 'SMTP_PORT'=> 25, 'smtp_user'=>'email', 'smtp_pass'=>'pass' );

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

$ this-> email-> from('email','George'); $ this-> email-> to('email'); $ this-> email-> subject('hey this is an email'); $ this-> email-> message('這是電子郵件的內容');

$ this-> email-> send(); }

一旦你已經試過了,這一切都已經工作一個通過這個閱讀:

http://codeigniter.com/forums/viewthread/84689/

0

MAMP不與OpenSSL的擴展發貨,但你可以自己創建它。詳情請參閱this教程