【问题标题】:getting error fsockopen(): unable to connect to smtp.googlemail.com:465 (Connection timed out) while sending email using codeigniter email class收到错误 fsockopen():使用 codeigniter 电子邮件类发送电子邮件时无法连接到 smtp.googlemail.com:465(连接超时)
【发布时间】:2017-06-08 09:42:36
【问题描述】:

我是 codeigniter 的新手,我正在尝试使用 codeigniter 电子邮件类发送电子邮件,但我收到错误 fsockopen():无法连接到 smtp.googlemail.com:465(连接超时)我试图解决这个问题,但是没有运气

public function signup()
{
    $this->form_validation->set_rules('email','Email','required|valid_email|is_unique[fbadmin.email]');
    $this->form_validation->set_error_delimiters("<p class='text-danger'>","</p>");
    if( $this->form_validation->run()==TRUE )
    {
        $data= $this->input->post();
        unset($data['submit']);
        //print_r($data);exit;
        $this->load->model('Fbadminmodel');
        if($this->Fbadminmodel->signup($data))
        {
            //$this->load->library('email');
            $config = array(
                'protocol'  =>'smtp',
                'smtp_host' =>'smtp.googlemail.com',
                'smtp_port' =>'465',
                'smtp_user' =>'anujk3313@gmail.com',
                'smtp_pass' =>'password',
                'mail_type' =>'html',
                'charset'   =>'utf-8'
                );
            //$this->email->initialize($config);
            $this->load->library('email', $config);
            $this->email->from('anujk3313@gmail.com','Anuj Kumar');
            $this->email->to($data);
            $this->email->message('www.haiviral.com');
            $this->email->set_newline("\r\n");

            if($this->email->send())
            {
                //$this->session->set_flashdata('feedback','Succefully Registred. Please verify your email');
                echo "mail send";
            }
            else
            {
                show_error($this->email->print_debugger());
            }
        }
        else
        {
            $this->load->view('fbadmin');
            $this->session->set_flashdata('feedback','Registration Failed');
        }
        //$this->session->flashdata('flash','Email Sent');
        $this->load->view('fbadmin');
    }
    else
    {
        echo validation_errors();
        $this->load->view('fbadmin');
    }
}

【问题讨论】:

  • 确保在您的 php.ini 和 'smtp_host' =&gt; 'ssl://smtp.googlemail.com' 中启用 extension=php_openssl.dll,将您的帖子作为 int 值传递
  • php_openssl.dll 已经打开
  • make 'smtp_host' =&gt; 'ssl://smtp.googlemail.com',将你的帖子作为 int 值传递
  • 我没有理解将您的帖子作为 int 值传递的意义抱歉@ShaileshSingh

标签: php codeigniter email


【解决方案1】:

有几件事可能是错误的。我要做的第一件事是设置您的smtp_timeout 设置:

$config = array(
    'smtp_timeout'=>'30', //<-- add this
    'protocol'  =>'smtp',
    'smtp_host' =>'smtp.googlemail.com',
    'smtp_port' =>'465',
    'smtp_user' =>'anujk3313@gmail.com',
    'smtp_pass' =>'password',
    'mail_type' =>'html',
    'charset'   =>'utf-8'
);

接下来我会检查您的主机是否允许您访问端口 465:

$fp = fsockopen("smtp.gmail.com", 465, $errno, $errstr, 10);
if (!$fp)
    echo "smtp.gmail.com 465  -  $errstr   ($errno)<br>\n";

如果还是不行,我会尝试禁用 gmail 的两步验证。

【讨论】:

  • 'smtp_timeout'=>'7' 已在电子邮件类文件中设置,但出现相同的错误@dave
【解决方案2】:

添加 ssl

$emailConfig = [
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'smtp_user' => 'xxx@gmail.com',
        'smtp_pass' => 'xxx',
        'mailtype' => 'html',
        'charset' => 'iso-8859-1'
    ];

【讨论】:

    猜你喜欢
    • 2017-03-13
    • 1970-01-01
    • 1970-01-01
    • 2014-11-07
    • 2014-03-08
    • 1970-01-01
    • 2016-05-14
    • 1970-01-01
    • 2014-11-29
    相关资源
    最近更新 更多