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

Hello,
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 -->
*****************************************************************************************************
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Test_email extends CI_Controller
{
function __construct()
{
parent::__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->set_newline("\r\n");
$this->email->from('[email protected]');
$this->email->to($receiver);
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
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)
           
Reply
#2

Hi,

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.

https://www.coderanks.com/article/sendin...ive-server

$localhosts = array(
'::1',
'127.0.0.1',
'localhost'
);

$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->load->library('email');
$this->email->initialize($config);
$this->email->from("From-Email");
$this->email->to("To-Email");
$this->email->subject("New user contacts");
$this->email->message($final_mail);
$flag = $this->email->send();

if($flag){
echo "Email sent";
}else{
echo "Email sending failed";
}
Reply
#3

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 )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB