Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method

前端 未结 6 678
余生分开走
余生分开走 2021-01-05 08:58

Iam using codeigniter

I exicuted the code on live server. got the following error using print_debugger()

Unable to send email using PHP SMTP.

6条回答
  •  青春惊慌失措
    2021-01-05 09:54

    I am using much time Run my configure code in localhost but it always gives me an error (Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.)

    But when run this Below code in my server it works for me.

    application>controller>Sendingemail_Controller.php

    public function send_mail() {
        $this->load->library('email');   
        $config = array();
        $config['protocol']     = "smtp"; // you can use 'mail' instead of 'sendmail or smtp'
        $config['smtp_host']    = "ssl://smtp.googlemail.com";// you can use 'smtp.googlemail.com' or 'smtp.gmail.com' instead of 'ssl://smtp.googlemail.com'
        $config['smtp_user']    = "my@gmail.com"; // client email gmail id
        $config['smtp_pass']    = "******"; // client password
        $config['smtp_port']    =  465;
        $config['smtp_crypto']  = 'ssl';
        $config['smtp_timeout'] = "";
        $config['mailtype']     = "html";
        $config['charset']      = "iso-8859-1";
        $config['newline']      = "\r\n";
        $config['wordwrap']     = TRUE;
        $config['validate']     = FALSE;
        $this->load->library('email', $config); // intializing email library, whitch is defiend in system
    
        $this->email->set_newline("\r\n"); // comuplsory line attechment because codeIgniter interacts with the SMTP server with regards to line break
    
        $from_email = $this->input->post('f_email'); // sender email, coming from my view page 
        $to_email = $this->input->post('email'); // reciever email, coming from my view page
        //Load email library
    
        $this->email->from($from_email);
        $this->email->to($to_email);
        $this->email->subject('Send Email Codeigniter'); 
        $this->email->message('The email send using codeigniter library');  // we can use html tag also beacause use $config['mailtype'] = 'HTML'
        //Send mail
        if($this->email->send()){
            $this->session->set_flashdata("email_sent","Congragulation Email Send Successfully.");
            echo "email_sent";
        }
        else{
            echo "email_not_sent";
            echo $this->email->print_debugger();  // If any error come, its run
        }
    }
    

    and my view page where I defined f_email and email comes through post method. application>view>emailtesting.php

    
        
         Send Email Codeigniter 
    
    
    session->flashdata('email_sent');
    echo form_open('/Sendingemail_Controller/send_mail');
    ?>
    
    
    
    
    
    

    if some error comes again please visit official documentation below:

    https://codeigniter.com/user_guide/libraries/email.html

提交回复
热议问题