Codeigniter 3 send email without smtp

2020-03-26 08:14发布

问题:

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('info@domain.com', '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.

回答1:

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']        = 'youremail@gmail.com';
$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('youremail@gmail.com')
     ->reply_to('youremail@gmail.com')
     ->to(someone@somedomain.com)
     ->subject("Subject")
     ->message("Your Message")
     ->set_mailtype('html')
     ->send();