2013-10-29 101 views
2

我正在開發我的android應用程序的web服務,我很難在我的電子郵件功能上運行良好。 我按照這個教程HERE發送郵件在Rest客戶端(Codeigniter)

,並在我的控制器我有這樣的:

function forgotPassword_get(){ 
     $this->load->model('model'); 

     $this->response->format = 'json'; 

     $email = $this->get('email'); 

    $config['protocol'] = 'sendmail'; 
    $config['mailpath'] = '/usr/sbin/sendmail'; 
    $config['charset'] = 'iso-8859-1'; 

    // gmail specific settings here 
    $config['smtp_host'] = 'smtp.gmail.com'; 
    $config['smtp_user'] = 'my email here'; 
    $config['smtp_pass'] = 'password here'; 
    $config['smtp_port'] = '465'; 

    $config['wordwrap'] = TRUE; 

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

     $this->email->from('mailfrom', 'sample name'); 
     $this->email->to('mailto'); 

     $this->email->subject('sample email'); 
     $this->email->message('sample message for email.'); 

     $this->email->send(); 

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

    } 

結果是

Your message has been successfully sent using the following protocol: sendmail 
    User-Agent: CodeIgniter 
    Date: Tue, 29 Oct 2013 15:45:57 +0800 
    From: "sample name" 
    X-Mailer: CodeIgniter 
    X-Priority: 3 (Normal) 
    Message-ID: <[email protected]> 
    Mime-Version: 1.0 
    Content-Type: text/plain; charset=iso-8859-1 
    Content-Transfer-Encoding: 8bit 

sample message for email. 

它說,郵件發送成功,但我認爲郵件沒有到達我的收件箱。

任何人都可以幫助我,我想我錯過了一些東西。 在此先感謝。

回答

2

你可能想試試這個:

$config['protocol'] = 'smtp'; 
$config['smtp_host'] = 'ssl://smtp.googlemail.com'; 
$config['smtp_port'] = '465'; 
$config['smtp_user'] = '[email protected]'; 
$config['smtp_pass'] = 'password Here'; 
$config['charset'] = 'utf-8'; 
$config['mailtype'] = 'html'; 
$config['newline'] = "\r\n"; 

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

我只是改變了你的配置項目。希望能幫助到你。

+0

正是我所做的。 – CaffeineShots

0

您是否在Gmail中啓用了SMTP訪問權限,如果我沒有記錯,您必須點擊Gmail中的某個複選框,如「允許第三方使用此帳戶發送郵件」。此外,這不是一種好的做法,因爲Gmail會不斷提醒您有人試圖訪問您的帳戶。

+0

不,我正在做它,但我試圖使用默認設置刪除「Gmail特定設置」,並使用一些一次性電子郵件仍然無法正常工作。 – CaffeineShots

+0

我發現沒有必要這樣做..它對配置項目的簡單正確操作就可以做到。 – CaffeineShots

相關問題