codeigniter $ this-> email-> send()在mail()不工作 [英] Codeigniter $this->email->send() not working while mail() does

查看:188
本文介绍了codeigniter $ this-> email-> send()在mail()不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么如果我尝试使用CI电子邮件类不发送电子邮件,而如果我使用本机PHP邮件()类工作。

I can't figure out why if I try to use the CI Email Class it doesn't send emails, while if I use the native PHP mail() Class works.

需要注意的是,有时我得到电子邮件发送,而实际上并没有发送,有时我得到错误我的服务器没有设置。

Has to be noted that sometimes I get "email sent" while is not actually sent and sometimes I get the error "my server is not setup".

我试图找出如何设置它,但没有...

I tried to figure out how to set it up but... nothing...

控制器代码如下:

 if($this->form_validation->run()){

                //Set Language
                $this->lang->load('site', $this->session->userdata('lang'));

                //Random key
                $user_valid_key = md5(uniqid());

                //Prepare email
                $this->load->library('email', array('mailtype' => 'html'));
                $this->email->from($this->config->item('email_signup_from'), 'Wondermark.net');
                $this->email->to($this->input->post('email'));
                $this->email->subject($this->lang->line('email_signup_subject'));

                //Format mail con %s per inserire i campi necessari
                $signup_msg = sprintf($this->lang->line('email_signup_message'), $this->input->post('fname'), base_url().'main/signup_confirm/'.$user_valid_key);

                $this->email->message((string)$signup_msg);

                if($this->email->send()){
                    //TODO: load view...
                    echo "email sent";
                }else{
                    $to = $this->input->post('email');
                    mail($to, 'test', 'Other sent option failed');
                    echo $this->input->post('email');
                    show_error($this->email->print_debugger());
                }

                //TODO: Add to db

            }else{

            // Form validation failed

}


推荐答案

p>

Use this setup email..

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

            $config['protocol']    = 'smtp';

            $config['smtp_host']    = 'ssl://smtp.gmail.com';

            $config['smtp_port']    = '465';

            $config['smtp_timeout'] = '7';

            $config['smtp_user']    = 'sender_mailid@gmail.com';

            $config['smtp_pass']    = 'password';

            $config['charset']    = 'utf-8';

            $config['newline']    = "\r\n";

            $config['mailtype'] = 'text'; // or html

            $config['validation'] = TRUE; // bool whether to validate email or not      

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


            $this->email->from('sender_mailid@gmail.com', 'sender_name');
            $this->email->to('recipient@gmail.com'); 


            $this->email->subject('Email Test');

            $this->email->message('Testing the email class.');  

            $this->email->send();

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

这篇关于codeigniter $ this-> email-> send()在mail()不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆