fsockopen():无法连接到smtp.gmail.com:465 codeigniter实时服务器

时间:2018-03-08 07:50:07

标签: codeigniter

此代码在实时服务器中出现错误。它在localhost中运行但不在实时服务器中运行。它给出了错误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);
        }
    }

1 个答案:

答案 0 :(得分:0)

首先,如果您在任何实时服务器中,则无需定义:

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

以上发送邮件的值:只需定义

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

完成了。它在实时服务器中工作。

相关问题