php - 无法使用 CODEIGNITER 发送邮件

标签 php codeigniter email ssl smtp

我一直在搜索这方面的信息,但找不到任何信息。这是我的代码(来自 Controller ):

public function send_mail(){
    $config = Array(
        'protocol' => 'smtp',
        'smt_host' => 'ssl://smtp.gmail.com',
        'smtp_port' => '465',
        'smtp_user' => 'mymail@gmail.com',
        'smtp_pass' => 'password',
        'charset' => 'iso-8859-1',
        'wordwrap' => TRUE
    );

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

    $this->email->set_newline("\r\n");

        $this->email->from('mymail@gmail.com', 'MyName');
        $this->email->to('mymail@gmail.com');

        $this->email->subject('Message');
        $this->email->message('Some text.');

        if ($this->email->send())
            echo "twas sent";
        else show_error ($this->email->print_debugger());      
}

现在我从调试器得到的错误是:

You did not specify a SMTP hostname.
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

Date: Tue, 9 May 2017 22:16:37 +0200
From: "MyName" <mymail@gmail.com>
Return-Path: <mymail@gmail.com>
To: mymail@gmail.com
Subject: =?ISO-8859-1?Q?=47=65=74=47=61=69=6E=73=20=4D=65=73=73=61=67=65?=
Reply-To: <mymail@gmail.com>
User-Agent: CodeIgniter
X-Sender: mymail@gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <591223a537e10@gmail.com>
Mime-Version: 1.0


Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit

Some text.

问题是我不明白我怎么没有指定 SMTP 主机名?我尝试过 465 和 587 之类的端口,尝试过“ssl://smtp.gmail.com”、“ssl://smtp.googlemail.com”、“smtp.gmail.com”等主机。

附言代替 mymail@gmail.com 和密码的是我真正的带密码的 gmail。

最佳答案

试试这个对我有用的代码

$from_email = " "; 
         $to_email = $this->input->post('email'); 

         //Load email library 

                $config['charset']    = 'utf-8';
                $config['newline']    = "\r\n";
                $config['mailtype'] = 'html'; 
                $config['validation'] = TRUE;      
        $this->email->initialize($config);
         $this->email->from($from_email, $this->input->post('fname')); 
         $this->email->to($to_email);
         $this->email->subject('Registration Success');
        $first_name=$this->input->post('fname');
        $email=$this->input->post('email');
            $email_subject = 'User Registration';                       

            $email_body = '';


         $this->email->message($email_body); 
            $this->email->send();
         //Send mail 

关于php - 无法使用 CODEIGNITER 发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43879225/

相关文章:

php - 在 Laravel 5 中什么时候不应该使用 get()

php - 使用 PHP for 和 foreach 循环从 JSON 数据中检索视频信息时遇到问题 - YouTube API 3

从 URL 参数获取 MySQL 行的 PHP 代码

php - 以 HTML 形式出现的数据直接在模式窗口中回显,但不显示在 PDF 中

php - Codeigniter -> 附上电子邮件

php - 从电子邮件表中收集所有电子邮件

php - 如何从 PHP 使用 SMPP 连接 SMSC 服务器

php - 如何在codeigniter中实现代码

php - Codeigniter 将参数传递给 Controller ​​索引

python - 使用 Python (smtplib) 发送邮件时指定发件人