Codeigniter 3 send email without smtp

10,465

Perfect solution is as below:

Step 1:

Download PhpMailer for CodeIgniter from below link.

https://github.com/ivantcholakov/codeigniter-phpmailer

Step 2:

Extract. Put third_party, libraries, helpers and config folder into your CI application folder.

There will just index file(s) in each folder that will ask you to replace. Click replace and continue.

Step 3:

Open application/config/email.php

And do some updates according to your email account. I am using gmail, so I am giving gmail settings as below.

$config['protocol']         = 'smtp'; // 'mail', 'sendmail', or 'smtp'
$config['mailpath']         = '/usr/sbin/sendmail';
$config['smtp_host']        = 'smtp.gmail.com'; // if you are using gmail
$config['smtp_user']        = '[email protected]';
$config['smtp_pass']        = 'sdkfjsk089sdfskKJ'; // App specific password
$config['smtp_port']        = 465; // for gmail
$config['smtp_timeout']     = 5;  

Step 4:

Now, in your controller where you want to send email. Use below code and its all done.

$this->load->library('email');
$this->email->from('[email protected]')
     ->reply_to('[email protected]')
     ->to([email protected])
     ->subject("Subject")
     ->message("Your Message")
     ->set_mailtype('html')
     ->send();
Share:
10,465
M Shahzad Khan
Author by

M Shahzad Khan

I am unique and that's my problem ;P

Updated on June 04, 2022

Comments

  • M Shahzad Khan
    M Shahzad Khan almost 2 years

    I am not receiving an email, though everything seems fine. May be hosting issue? Any suggestion will be appreciated. Here is my code

        $this->load->library('email');
        $this->email->from('[email protected]', 'Name');
        $this->email->to($seller_email);
        $this->email->subject('This is subject');
        $this->email->message('This is message!');
        $this->email->send();
        echo $this->email->print_debugger();
    

    print_debugger function returns empty. Let me know you guys comments.