0
votes

I've been searching information on this but can't find any. Here is my code (from controller):

public function send_mail(){
    $config = Array(
        'protocol' => 'smtp',
        'smt_host' => 'ssl://smtp.gmail.com',
        'smtp_port' => '465',
        'smtp_user' => '[email protected]',
        'smtp_pass' => 'password',
        'charset' => 'iso-8859-1',
        'wordwrap' => TRUE
    );

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

    $this->email->set_newline("\r\n");

        $this->email->from('[email protected]', 'MyName');
        $this->email->to('[email protected]');

        $this->email->subject('Message');
        $this->email->message('Some text.');

        if ($this->email->send())
            echo "twas sent";
        else show_error ($this->email->print_debugger());      
}

Now the error I get from debugger is:

You did not specify a SMTP hostname.
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

Date: Tue, 9 May 2017 22:16:37 +0200
From: "MyName" <[email protected]>
Return-Path: <[email protected]>
To: [email protected]
Subject: =?ISO-8859-1?Q?=47=65=74=47=61=69=6E=73=20=4D=65=73=73=61=67=65?=
Reply-To: <[email protected]>
User-Agent: CodeIgniter
X-Sender: [email protected]
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
Mime-Version: 1.0


Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit

Some text.

The thing is I cannot understand how did I not specify SMTP hostname? I've tried ports like 465 and 587, tried hosts like 'ssl://smtp.gmail.com', 'ssl://smtp.googlemail.com', 'smtp.gmail.com', etc.

P.S. Instead of [email protected] and password stands my real gmail with password.

1
Spelled smt_host wrong? - Alex Howansky
Would you like to tell dev stack ? - Waqas Ahmed
If your sending mail on localhost you might need to set up some back end settings youtube.com/watch?v=TO7MfDcM-Ho - Mr. ED
the problem was spelling and settings of gmail's account itself... thank you guys, helped me a lot! - zilijonas
try to change the host become this ssl://smtp.googlemail.com - Kelvin

1 Answers

1
votes

Try this code it is working for me

$from_email = " "; 
         $to_email = $this->input->post('email'); 

         //Load email library 

                $config['charset']    = 'utf-8';
                $config['newline']    = "\r\n";
                $config['mailtype'] = 'html'; 
                $config['validation'] = TRUE;      
        $this->email->initialize($config);
         $this->email->from($from_email, $this->input->post('fname')); 
         $this->email->to($to_email);
         $this->email->subject('Registration Success');
        $first_name=$this->input->post('fname');
        $email=$this->input->post('email');
            $email_subject = 'User Registration';                       

            $email_body = '';


         $this->email->message($email_body); 
            $this->email->send();
         //Send mail