首页 > 解决方案 > Codeigniter 电子邮件在服务器 fsockopen() 中不起作用:无法连接到 ssl://smtp.googlemail.com:465(连接被拒绝)

问题描述

请在codeigniter电子邮件中帮助我,我尝试了很多次但没有成功,它在本地主机上工作但在服务器上没有工作。

错误:

遇到 PHP 错误

严重性:警告

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

文件名:库/Email.php

行号:2069

回溯:

文件:/home/b4ger7ik8el2/public_html/account/application/controllers/Welcome.php 行:105 功能:发送

文件:/home/b4ger7ik8el2/public_html/account/index.php 行:315 功能:require_once

$config = array(
                        'protocol' => 'smtp',
                        'smtp_host' => 'ssl://smtp.googlemail.com',
                        'smtp_port' => 465,
                        'smtp_user' => 'Email', // change it to yours
                        'smtp_pass' => 'Pasword', // change it to yours
                        'mailtype' => 'html',
                        'charset' => 'iso-8859-1',
                        'wordwrap' => TRUE
                    );

                    $message =  "
                                <html>
                                <head>
                                    <title>Verification Code</title>
                                </head>
                                <body>
                                    <h2>Thank you for Registering.</h2>
                                    <p>Dear:".$this->input->POST('firstname')."</p>
                                    <p>Email: ".$this->input->POST('user_email')."</p>
                                    <p>Please click the link below to activate your account.</p>
                                    <h4><a href='".base_url()."welcome/activate/".$email=$this->input->POST('user_email')."/'>Activate My Account</a></h4>
                                </body>
                                </html>
                                ";

                    $this->load->library('email', $config);
                    $this->email->set_newline("\r\n");
                    $this->email->from($config['smtp_user']);
                    $this->email->to($this->input->POST('user_email'));
                    $this->email->subject('Signup Verification Email');
                    $this->email->message($message);

                    //sending email
                    if($this->email->send()){
                        $this->session->set_flashdata('Success','Your Account Has Been Created Please Check your email and verify your account..!');
                    }
                    else{
                        $this->session->set_flashdata('message', $this->email->print_debugger());

                    }

标签: phpemailcodeigniter-3

解决方案


您只需要从配置数组中的 SMTP 字符串中删除 SSL 部分,

config = array(
               'protocol' => 'smtp',
                'smtp_host' => 'smtp.googlemail.com',
                'smtp_port' => 465,
                'smtp_user' => 'Email', // change it to yours
                'smtp_pass' => 'Pasword', // change it to yours
                'mailtype' => 'html',
                'charset' => 'iso-8859-1',
                'wordwrap' => TRUE
                    );

推荐阅读