2017-03-16 33 views
1

我想發送忘記密碼鏈接到Gmail。但無法取得成功。郵件不發送/刪除php codeigniter

這是我的小代碼。我在這裏有我的配置文件。如果需要更改,請提出建議。我使用兩個Gmail帳戶將郵件從一個Gmail帳戶發送到其他Gmail帳戶。

這裏是我的配置文件email.php

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 
$config = Array(
     $config['protocol'] = 'smtp', 
     $config['smtp_host'] = 'ssl://smtp.gmail.com', 
     $config['smtp_port'] = '465', 
     $config['smtp_timeout'] = '7', 
     $config['smtp_user'] = '[email protected]', 
     $config['smtp_pass'] = '123', 
     $config['charset'] = 'utf-8', 
     $config['newline'] = "\r\n", 
     $config['mailtype'] = 'text', // or html 
     $config['validation'] = TRUE // bool whether to validate email or not 
    ); 

這裏是我的郵件傳遞代碼。

if($this->form_validation->run()) 
      { 
       //echo 1; 
       //echo validation_errors(); 
       $this->load->library('email'); 
       $reset_key = md5(uniqid());    
       $this->load->model('User_Model'); 
       if($this->User_Model->update_reset_key($reset_key)) 
       {     

        $this->email->from('[email protected]', 'data-+-'); 
        $this->email->to($this->input->post('email')); 
        $this->email->subject('Reset you account password at Mahesh Makwana'); 
        $message = "<p><h4>You or someone request to reset your password.</h4></p>"; 
        $message.="<a href='".base_url(). "reset_password/".$reset_key."'>Click here to reset your password</a>"; 
        $this->email->message($message); 
         if($this->email->send()) 
         { 
          echo 'Kindly check your email '.$this->input->post('email').' to reset your password'; 
         } 
         else 
         { 
          echo 'Cannot send email! Kindly contact to our customer service to help you.!'; 
         } 
        } 
        else{ 
         echo 1; 
        } 
       } 
       else 
       { 
        //echo 0; 
        //echo validation_errors(); 
        $this->load->view('include/forgetpassword'); 
       } 

回答

0

代碼沒有錯。這可能是因爲谷歌的安全。嘗試允許在谷歌帳戶設置「安全性較低的應用程序的訪問登錄到您的帳戶後

https://www.google.com/settings/security/lesssecureapps

+0

我認爲你是正確的,因爲當我嘗試發送郵件,谷歌郵件我與**審覈被阻止的登錄嘗試**。 – Mahi

+0

郵件收件人(收件人)是否有此功能來接收郵件。 – Mahi

+0

只有郵件發件人帳號應該允許應用程序 –

0

管理您的配置設置,如下圖所示:

 $config['protocol'] = 'smtp'; 
     $config['smtp_host'] = 'ssl://smtp.gmail.com'; 
     $config['smtp_port'] = '465'; 
     $config['smtp_timeout'] = '7'; 
     $config['smtp_user'] = '[email protected]'; 
     $config['smtp_pass'] = 'xxxxx'; 
     $config['charset'] = 'utf-8'; 
     $config['newline'] = "\r\n"; 
     $config['mailtype'] = 'text' // or html 
     $config['validation'] = TRUE; // bool whether to validate email or not 

然後加載email庫集配置後使用$this->email->initialize($config);

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

您可以在不加載'$ this-> load-> library('email');'library的情況下編寫代碼。但它發送我的郵件垃圾郵件。你們倆**和** Kuldeep singh **都是對的。但我只能接受一個答案。 – Mahi