电子邮件未发送codeigniter..getting错误

时间:2017-10-18 06:18:24

标签: php codeigniter email

发送邮件时出错。无法验证密码。错误:535-5.7.8不接受用户名和密码。如需了解更多信息,请访问535 5.7.8 https://support.google.com/mail/?p=BadCredentials d190sm18198379pgc.53 - gsmtp 无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法发送邮件..

<?php
public function sendmail()
{

        if($this->input->post()){
                $email=$this->input->post('email');
                $config = Array(
                    'protocol' => 'smtp',
                    'mailtype' => 'html',
                    'smtp_host' => 'ssl://smtp.gmail.com',
                    'smtp_port' => '465',
                    'smtp_user' => 'xxx@gmail.com', 
                    'smtp_pass' => 'xxxxxxx', 
                    'useragent' => 'CodeIgniter',
                    'crlf' => '\r\n',      
                    'newline' => '\r\n'   

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

                $password="<p>This email has been sent as a request to reset our password</p>";
                $from='codescart123@gmail.com';
                $to=$email;
                $subject='forget password';                        
                $this->email->from($from);
                $this->email->to($to);
                $this->email->subject($subject);
                $this->email->message($password);
                if($this->email->send()){
                    $this->session->set_flashdata('email','We sent your password to your Email...!');

                }
                else{            
                    echo $this->email->print_debugger();
                }

        }

    else{
        $this->load->view('adminlogin');
    }

}

2 个答案:

答案 0 :(得分:0)

首先,正如您的错误所说,您需要正确检查ID,密码。

以下是完整代码:试试这个

<?php
public function sendmail()
{

    if($this->input->post()){
        $email=$this->input->post('email');

        $config = Array(
            protocol' => 'smtp',
            'smtp_host' => 'ssl://smtp.googlemail.com', //Your Host
            'smtp_port' => '25', 
            'smtp_user' => 'xxx@gmail.com', // change it to yours, server email
            'smtp_pass' => 'xxx',
            'mailtype' => 'html',
            'charset' => 'iso-8859-1',
            'wordwrap' => TRUE   

        );

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

        $password="<p>This email has been sent as a request to reset our password</p>";
        $from='codescart123@gmail.com';
        $to=$email;
        $subject='forget password';                        
        $this->email->from($from);
        $this->email->to($to);
        $this->email->subject($subject);
        $this->email->message($password);
        if($this->email->send()){
            $this->session->set_flashdata('email','We sent your password to your Email...!');

        }
        else{            
            echo $this->email->print_debugger();
        }

    } else {
        $this->load->view('adminlogin');
    }

}

答案 1 :(得分:0)

嗨,我认为这可以解决您的问题。

如果您使用gmail发送问题,请花一些时间尝试此解决方案。

  • 'smtp_host' => 'ssl://smtp.gmail.com'更改为'smtp_host' => 'smtp.gmail.com'
  • 添加'smtp_crypto' => 'tls'
  • 'smtp_port' => '465'更改为'smtp_port' => '587'
  • 在您的电子邮件帐户中创建一个应用程序密码,并使用它来换取您的应用凭据中的真实密码。
  • 在您的电子邮件帐户中启用安全性较低的应用。

这些是我之前遇到问题时所做的解决方案。希望它有所帮助。