fsockopen():无法连接到ssl://smtp.googlemail.com:465(连接被拒绝)在实时服务器godaddy上。它在localhost上的工作

时间:2018-04-04 05:58:46

标签: php codeigniter email

我有以下功能可以在localhost上运行,但它不能在live server godaddy上运行。 它抛出警告:

  

fsockopen():无法连接到ssl://smtp.googlemail.com:465   (连接被拒绝)

这是我的模特函数

  public function check()
    {
        $name   = 'sangram';
        $email  = 'sangram.preciseit@gmail.com';
        $phone  = '12456789';
        $message= 'testing';

        $to = 'sangram.preciseit@gmail.com';
        $sub = 'Enquiry';
        $msg="<p>Name:$name</p><p>Email: $email</p><p>Contact Number: $phone</p><p>Message: $message</p>";

        $configGmail = array();
        $configGmail['protocol']        = 'smtp';
        $configGmail['smtp_host']    = 'ssl://smtp.googlemail.com';
        $configGmail['smtp_port']    = '465';
        $configGmail['mailtype']        = 'html';
        $configGmail['charset']     = 'utf-8';
        $configGmail['newline']     = "\r\n";

        // new mailid chnaged on 1st-dec-2016
        $configGmail['smtp_user']    = 'emailaddress@gmail.com';
        $configGmail['smtp_pass']    = 'mypassword';

        $configGmail['wordwrap']    = TRUE;

        $this->load->library('email');
        $this->email->initialize($configGmail);

        $this->email->from('emailaddress@gmail.com',"XYZ");

        $this->email->to($to);
        $this->email->subject($sub);
        $msg    =   $msg;
        $this->email->message($msg);

        if($this->email->send())
        {
            echo "mail send";
        }
        else{
            echo "mail not send";
        }
    }

请告诉我该怎么办? 提前致谢

1 个答案:

答案 0 :(得分:0)

请从ssl删除ssl://smtp.googlemail.com

更改配置数组,添加smtp_crypto并将其值设置为ssl

    $configGmail = array();
    $configGmail['protocol']    = 'smtp';
    $configGmail['smtp_host']   = 'smtp.googlemail.com';
    $configGmail['smtp_port']   = '465';
    $configGmail['mailtype']    = 'html';
    $configGmail['charset']     = 'utf-8';
    $configGmail['newline']     = "\r\n";


    $configGmail['smtp_user']    = 'emailaddress@gmail.com';
    $configGmail['smtp_pass']    = 'mypassword';
    $configGmail['smtp_crypto']  = 'ssl';  
    $configGmail['wordwrap']     = TRUE;

希望这有帮助。