【问题标题】:PHP: Emails only working for certain email clientsPHP:电子邮件仅适用于某些电子邮件客户端
【发布时间】:2013-01-31 09:27:51
【问题描述】:

我正在创建一个使用 Codeigniter 和 Ion Auth Library 的网站。

我已经设置了一个注册/登录/忘记密码,除了忘记密码设置的问题之外,所有这些都可以工作。

如果用户的邮箱使用hotmail、yahoo、gmail等,他们收到的邮件正常,可以重置密码和数据库中的数据更改。

我的个人域电子邮件地址在 Outlook 和 Mail 中接收此电子邮件时遇到问题,因此看起来可能与 Exchange 有关?

我还启用了具有 Outlook 的计算机上的日志设置,并且在测试发送电子邮件时没有记录任何内容,因此它不会阻止电子邮件。

现在我有一个包含电子邮件配置设置的数组,我不确定它是否与主机、协议、标题有关?!或任何其他设置,但我将在下面提供一些我所拥有的信息。如果有人有任何信息、链接、sn-ps 或想法,这将是一个很大的帮助。

使用 Ion Auth,我只是将代码保留在原来的位置,并将其更改为我在配置文件中的设置:

配置

   $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);
    }

忘记密码的图书馆功能:

/**
     * 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;
        }
    }

【问题讨论】:

  • 您查看过 host.url.com 上的电子邮件日志吗?您是否使用 live 发送电子邮件?如果是这样,您是否可以先访问开发邮件服务器进行测试?
  • 我目前正在本地主机上开发,也上传到服务器上,但没有收到相关信息。调试时,它说电子邮件已发送,但说电子邮件可能无法读取 MIME 编码的电子邮件 - 不确定这是否可以在我的配置文件中更改?还尝试了纯文本,将所有内容都删除,但仍然没有运气甚至错误。我使用过@hotmail.co.uk,并且在 Outlook Live 浏览器、gmail 浏览器和 yahoo 浏览器中收到了电子邮件。不幸的是,我无法访问开发邮件服务器。
  • 可以先在本地安装hMail Server之类的东西来测试本地发送邮件吗?您确实可以查看邮件服务器的实际日志。
  • 我仅限于我可以安装的内容以及公司限制和访问范围内的位置。我尝试打开 Mail 的库/脚本文件,但我无权访问它。在另一台使用 Windows 的计算机上,我启用了日志系统,但没有任何显示...试图尽可能地缩小范围,但现在碰壁了。
  • 本地开发时发送邮件,可以使用gmail$config = Array( 'protocol' => 'smtp', 'smtp_host' => 'ssl://smtp.googlemail.com', 'smtp_port' => 465, 'smtp_user' => 'whatever@gmail.com', 'smtp_pass' => '', );

标签: php codeigniter email ion-auth


【解决方案1】:

此时我也遇到了同样的问题。这是我的解决方案,基于此论坛帖子,它确实帮助我理解了这个错误。

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

就我而言,问题是我使用存储库中的语言文件对 IonAuth 进行多语言设置。在德语语言文件中,您会发现“email_forgotten_password_subject”语言行的特殊字符“ü”。

Codeigniter 邮件类未使用主题配置中的编码。所以 specialchar 编码错误,出现 smtp_mailer 错误。

我创建了一个文件 application/libraries/MY_Email.php 来将使用的主题设置方法与此内容挂钩:

<?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 正在以正确的方式对主题进行编码,我们都去周末喝点啤酒。

我希望我的解决方案与您的问题相符。

干杯

【讨论】:

    【解决方案2】:

    我不知道您需要的确切配置。无论这里是我自己的 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('mahbub.kuet@gmail.com', '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;   
        }    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 1970-01-01
      • 2015-09-02
      • 1970-01-01
      • 2011-07-28
      相关资源
      最近更新 更多