-3

This code gives me an error when it is in live server. Its running in localhost but not running in live server. It gives error fsockopen():unable to connect

public function forgetPassword()
{
    if(isset($_POST['email']) && !empty($_POST['email']))
    {
        $result = $this->Db_Function->loadDataForUpdate('wc_usr','wc_email',$_POST['email'],'nor');
        if($result)
        {        
            $config = array(
                'protocol' => 'smtp',
                'smtp_host' => 'smtp.gmail.com',
                'smtp_user' => 'nileshivarni@gmail.com',
                'smtp_pass' => 'Nilesh@1234',
                'smtp_port' => 465,
                'mailtype' => 'html',
                'charset' => 'utf-8',
                'newline' => "\r\n"
            );
            $this->email->initialize($config);
            $this->email->from('nileshivarni@gmail.com','Varni IT Solution');
            $this->email->to($_POST['email']);
            $this->email->subject('Password Recovery');
            $msg = '<html><head></head><body>';
            $msg .= '<p>Dear ' . $result[0]['wc_fullname']. ',</p>';
            $msg .= '<p> <strong >Here is your Email and Password</strong></p>';
            $msg .='<p>Email    : <strong>'.$result[0]['wc_email'].'</strong></p>';
            $msg .='<p>Password : <strong>'.base64_decode($result[0]['wc_password']).'</strong></p>';
            $msg .='<p>Thank you</p>';
            $msg .='<p>The team at Varni IT Solution</p>';
            $msg .='</body></html>' ;

            $this->email->message($msg);
            if($this->email->send()){
                $response['error'] = '1';
                $response['success'] = "Your Password is successfully send to your email address !";
                echo json_encode($response);                            
            } 
        }
        else
        {
            $response['error']='2';
            $response['errorMsg']='Sorry ! Your Email is not registered with us!';
            echo json_encode($response);
        }
    }
André Kool
  • 4,880
  • 12
  • 34
  • 44
Guru Broz
  • 1
  • 2
  • https://stackoverflow.com/questions/1555145/sending-email-with-gmail-smtp-with-codeigniter-email-library –  Mar 08 '18 at 08:27

1 Answers1

0

first of all if you are in any live server then it's not necessary to define :

$config = array( 'protocol' => 'smtp',
            'smtp_host' => 'smtp.gmail.com',
            'smtp_user' => 'nileshivarni@gmail.com',
            'smtp_pass' => 'Nilesh@1234',
            'smtp_port' => 465);

above values for sending a mail : just define

$config = array(
            'mailtype' => 'html',
            'charset' => 'utf-8',
            'newline' => "\r\n");

That's completed. It's work in live server.

Guru Broz
  • 1
  • 2