无法使用codeigniter电子邮件库和google smtp设置向valide用户发送电子邮件

时间:2018-06-14 15:40:36

标签: php codeigniter codeigniter-2 codeigniter-3

我在我的controllei中的公共函数中有这个代码我试图在注册后通过向用户发送邮件来验证用户。 注册后,用户不会收到任何电子邮件。

if ($validation_code)
                {

                    $email_template = $this->template_model->get_email_template(1);

                    if($email_template['status'] == "1") {

                        // build the validation URL
                        $encrypted_email = sha1($this->input->post('email', TRUE));
                        $validation_url  = base_url('user/validate') . "?e={$encrypted_email}&c={$validation_code}";


                        $site_name = $this->settings->site_name;
                        $name_user = $this->input->post('first_name') . ' ' . $this->input->post('last_name');

                        $rawstring = $email_template['message'];


                        $placeholders = array('[SITE_NAME]', '[CHECK_LINK]', '[NAME]');

                        $vals_1 = array($site_name, $validation_url, $name_user);


                        $str_1 = str_replace($placeholders, $vals_1, $rawstring);

                        $this -> email -> from($this->settings->site_email, $this->settings->site_name);
                        $this->email->to($this->input->post('email', TRUE));
                        //$this -> email -> to($user['email']);
                        $this -> email -> subject($email_template['title']);

                        $this -> email -> message($str_1);

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

用户注册时未收到任何电子邮件。我尝试过使用不同的ports.i也在php.ini中启用了openssl。任何帮助将不胜感激。 smtp设置

<?php
 $config['useragent'] = 'CodeIgniter';
 $config['protocol'] = 'smtp';
 //$config['mailpath'] = '/usr/sbin/sendmail';
 $config['smtp_host'] = 'ssl://smtp.gmail.com ';
 $config['smtp_user'] = 'xxxxxx';
 $config['smtp_pass'] = 'xxxxxx';
 $config['smtp_port'] = 465; 
 $config['smtp_timeout'] = 5;
 $config['wordwrap'] = TRUE;
 $config['wrapchars'] = 76;
 $config['mailtype'] = 'html';
 $config['charset'] = 'utf-8';
 $config['validate'] = FALSE;
 $config['priority'] = 3;
 $config['crlf'] = "\r\n";
 $config['newline'] = "\r\n";
 $config['bcc_batch_mode'] = FALSE;
 $config['bcc_batch_size'] = 200;
 ?>

0 个答案:

没有答案