2013-02-15 107 views
1

我正在創建一個使用Codeigniter和Ion Auth Library的網站。PHP:電子郵件只適用於某些電子郵件客戶端

我已經設置了一個註冊/登錄/忘記密碼,除了忘記密碼設置的問題之外,這些密碼都可以使用。

如果用戶的電子郵件地址是使用hotmail,yahoo,gmail等他們收到的電子郵件罰款,可以重置密碼和數據庫中的數據更改。

我在接收此電子郵件的個人域名電子郵件地址在Outlook和Mail中遇到問題,因此它看起來可能與Exchange有關?

我還啓用了具有Outlook的計算機上的日誌設置,並且在測試發送電子郵件時什麼也沒有記錄,所以它不像它阻止電子郵件。

現在我有一個數組的電子郵件配置設置,我不確定它是否可以與主機,協議,頭文件?或任何其他設置,但我會提供一些信息,以我的東西。如果任何人有任何信息,鏈接,片段或想法,這將是一個很大的幫助。

對於使用離子驗證我剛纔一直在那裏它是,它改變了我的配置文件設置代碼:

CONFIG

$config['use_ci_email'] = FALSE; // Send Email using the builtin CI email class, if false it will return the code and the identity 
    $config['email_config'] = array(
     'protocol'=> 'mail', 
     'mailtype' => 'html', 
     'charset' =>'utf-8', 
     'smpt_host' =>'smpt.url.com', 
     'smpt_user'=> 'ssl://smtp.live.com', 
     'smtp_port' => '25', 
     'validate' => TRUE, 
     'priority' => 1 

    ); 

控制器,用於忘記密碼

//forgot password 
    function forgot_password() { 

     $this->form_validation->set_rules('email', 'Email Address', 'required'); 
     if ($this->form_validation->run() == false) { 

      //setup the input 
      $this->data['email'] = array('name' => 'email', 
       'id' => 'email', 
      ); 

      if ($this->config->item('identity', 'ion_auth') == 'username'){ 
       $this->data['identity_label'] = 'Username'; 
      }else{ 
       $this->data['identity_label'] = 'Email'; 
      } 

      //set any errors and display the form 
      $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message'); 
      $this->_render_page('forgot_password', $this->data); 
     }else{ 
      // get identity for that email 
      $config_tables = $this->config->item('tables', 'ion_auth'); 
      $identity = $this->db->where('email', $this->input->post('email'))->limit('1')->get($config_tables['users'])->row(); 

      //run the forgotten password method to email an activation code to the user 
      $forgotten = $this->ion_auth->forgotten_password($identity->{$this->config->item('identity', 'ion_auth')}); 

      if ($forgotten) { 
       $this->session->set_flashdata('message', $this->ion_auth->messages()); 
       redirect("login", 'refresh'); //we should display a confirmation page here instead of the login page 
      }else{ 
       $this->session->set_flashdata('message', $this->ion_auth->errors()); 
       redirect("forgot_password", 'refresh'); 
      } 
     } 
    } 


    function _get_csrf_nonce() { 
     $this->load->helper('string'); 
     $key = random_string('alnum', 8); 
     $value = random_string('alnum', 20); 
     $this->session->set_flashdata('csrfkey', $key); 
     $this->session->set_flashdata('csrfvalue', $value); 

     return array($key => $value); 
    } 

庫函數for得到密碼:

/** 
    * forgotten password feature 
    **/ 
    public function forgotten_password($identity) //changed $email to $identity 
{ 
     if ($this->ion_auth_model->forgotten_password($identity)) //changed 
     { 
      // Get user information 
      $user = $this->where($this->config->item('identity', 'ion_auth'), $identity)->users()->row(); //changed to get_user_by_identity from email 

      if ($user) 
      { 
       $data = array(
        'identity'  => $user->{$this->config->item('identity', 'ion_auth')}, 
        'forgotten_password_code' => $user->forgotten_password_code 
       ); 

       if(!$this->config->item('email_config', 'ion_auth')) 
       { 
        $this->set_message('forgot_password_successful'); 
        return $data; 
       } 
       else 
       { 
        $message = $this->load->view($this->config->item('email_templates', 'ion_auth').$this->config->item('email_forgot_password', 'ion_auth'), $data, true); 
        $this->email->clear(); 
        $this->email->from($this->config->item('admin_email', 'ion_auth'), $this->config->item('site_title', 'ion_auth')); 
        $this->email->to($user->email); 
        $this->email->subject($this->config->item('site_title', 'ion_auth') . ' - ' . $this->lang->line('email_forgotten_password_subject')); 
        $this->email->message($message); 

        if ($this->email->send()) 
        { 
         $this->set_message('forgot_password_successful'); 
         return TRUE; 
        } 
        else 
        { 
         $this->set_error('forgot_password_unsuccessful'); 
         return FALSE; 
        } 
       } 
      } 
      else 
      { 
       $this->set_error('forgot_password_unsuccessful'); 
       return FALSE; 
      } 
     } 
     else 
     { 
      $this->set_error('forgot_password_unsuccessful'); 
      return FALSE; 
     } 
    } 
+0

你看過在host.url.com上的電子郵件日誌嗎?您是否使用電子郵件直播?如果是這樣,你有權訪問開發郵件服務器進行測試嗎? – LeonardChallis 2013-02-15 11:52:58

+0

我目前正在本地主機上開發,也上傳到服務器上,沒有收到相關信息。當調試它說的是電子郵件發送,但表示電子郵件可能無法讀取MIME編碼的電子郵件 - 不知道這是我可以改變我的配置文件?還嘗試了純文本,將所有內容都鑲嵌到後面,但仍然不是運氣甚至錯誤。我使用了@ hotmail.co.uk,並且在Outlook Live瀏覽器,Gmail瀏覽器和雅虎瀏覽器中收到了該電子郵件。我不幸的是無法訪問開發郵件服務器。 – Shimsham84 2013-02-15 12:02:33

+0

您可以在本地安裝類似hMail Server的服務器來測試郵件本地發送嗎?你真的可以看到郵件服務器的實際日誌。 – LeonardChallis 2013-02-15 12:04:35

回答

0

我不知道你需要的確切配置。無論這裏是我自己的send_mail()函數使用CI電子郵件庫。它可以幫助你。不過,我總是使用ION AUTH,並且在發送郵件時我從不面臨問題。

/* 
* Send an email. 
* $info array must have following information : 
* $info = array(
*  'to_email'  => 
*  'to_name'  => 
*  'from_email' => 
*  'from_name'  => 
*  'subject'  => 
*  'body'   => 
*  'reply_to'  => 
*) 
*/ 
if (! function_exists('send_email')) 
{ 
    function send_email($info) 
    { 
     $CI = & get_instance(); 

     // ========================================================================================== 
     $CI->load->library('email'); 

     $config['protocol'] = 'sendmail'; 
     $config['charset'] = 'iso-8859-1'; 
     $config['wordwrap'] = TRUE; 
     $config['mailtype'] = 'html'; 

     $CI->email->initialize($config); 

     $CI->email->clear(); 
     $CI->email->set_newline("\r\n"); 
     // ========================================================================================= 

     $CI->email->from($info['from_email'], $info['from_name']); 
     $CI->email->to($info['to_email'], $info['to_name']); 
     $CI->email->cc('[email protected]', 'MAHBUB'); 

     $CI->email->subject($info['subject']); 
     $CI->email->message($info['body']); 

     $CI->email->reply_to($info['reply_to'], "No reply"); 

     if($CI->email->send()) return TRUE; 

     return FALSE; 
    }  
} 
0

我在這一刻也有同樣的問題。這是我的解決方案,基於這個論壇帖子,這真的幫助我瞭解這個錯誤。

http://ellislab.com/forums/viewreply/785297/

在我的情況下,問題是使用的語言文件從存儲庫IonAuth我多語言設置。在德語語言文件中,您會發現'email_forgotten_password_subject'語言行的特殊字符'ü'。

Codeigniter郵件類未使用主題配置中的編碼。所以specialchar編碼不好,並出現smtp_mailer錯誤。

我已經創建了一個文件,應用程序/庫/ MY_Email.php與此內容掛鉤的使用受setter方法:

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class MY_Email extends CI_Email 
{ 
    /** 
    * Set Email Subject 
    * 
    * @access public 
    * @param string 
    * @return void 
    */ 
    function subject($subject) 
    { 
     $subject = '=?'. $this->charset .'?B?'. base64_encode($subject) .'?='; 
     $this->_set_header('Subject', $subject); 
    } 
} 

現在Mailclass被編碼題目的正確方法,我們都進入週末,喝些啤酒。

我希望我的解決方案符合您的問題。

乾杯

相關問題