Search code examples
phpcodeignitersmtpgmail

Mail not sending from hosted codeigniter application


Gmail smtp is configured successfully in localhost, but the same thing not working in remote after moved to godaddy server. It is not send any mails from the application.

This is my gmail smtp configuration.

$config ['protocol'] = 'smtp';
$config ['smtp_host'] = 'ssl://smtp.gmail.com';
$config ['smtp_port'] = '465';
$config ['smtp_user'] = '[email protected]';
$config ['smtp_pass'] = 'xxxx';
$config ['mailtype'] = 'html';
$config ['charset'] = 'iso-8859-1';
$config ['wordwrap'] = TRUE;
$config ['newline'] = "\r\n";

Solution

  • try this:

    function send_email(){
    $config = array(
                'protocol' => 'smtp',
                  'smtp_host' => 'ssl://smtp.gmail.com',
                  'smtp_port' => 465,
                 'smtp_user' => '[email protected]', // change it to yours
                 'smtp_pass' => 'adcxc', // change it to yours
                 'mailtype' => 'html',
                 'charset' => 'UTF-8',
                 'wordwrap' => TRUE
              ); 
            $this->load->library('email',$config);
            $this->email->set_newline("\r\n");
            $this->email->from([email protected]);
            $this->email->to([email protected]);
    
    
            $this->email->subject("test");
            $this->email->message("message");
    
            $result = $this->email->send();
    
    
            if ($result) {
                echo  "Success";
    
            }
            else{
                echo $this->email->print_debugger();
            }
    }