Welcome Guest, Not a member yet? Register   Sign In
email in codeigniter works fine in localhost, but not working on live environment

I am using codeigniter email library to send email. the code runs fine in localhost but it gives several warnings on live environment.

My code -->
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Test_email extends CI_Controller
function __construct()

function index()
$receiver = '[email protected]';
$subject = 'HOLAA User Authentication';
$message = 'HELLO USER, You Registered successfully..';

//email code
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '[email protected]',
'smtp_pass' => 'tauyqmdtyplkgeew',
'mailtype'  => 'html', 
'charset'   => 'iso-8859-1'
$this->load->library('email', $config);
$this->email->from('[email protected]');
echo $this->email->print_debugger();


It is running fine on localhost, but when I put that code on -->http://uat.holaa.in/index.php/Test_email  It is giving several warnings & email sending fails(Plz. visit this link to know more about error I am getting. I turned email debugger on). Few snapshots of successful email sent message through localhost & error on live platform I have attached with this post. Please look at photos attached with this post.

Thank you in advance  Smile

Attached Files Thumbnail(s)


you can use following approach to send email from localhost and live server as well. it works for me perfectly. For more details, you can check this article of Coderanks.com.


$localhosts = array(

$protocol = 'mail';
if (in_array($_SERVER['REMOTE_ADDR'], $localhosts)) {
$protocol = 'smtp';

$config = array(
'protocol' => $protocol,
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'Your-Email',
'smtp_pass' => 'Your-Email-Password',
'mailtype' => 'html',
'starttls' => true,
'newline' => "\r\n",

$this->email->subject("New user contacts");
$flag = $this->email->send();

echo "Email sent";
echo "Email sending failed";

Fix your user and password you should never display on a live server or in the forums!
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

Theme © iAndrew 2016 - Forum software by © MyBB