0

我有以下代码

            ini_set("SMTP","ssl://smtp.gmail.com");
            ini_set("smtp_port","587");

            $config['protocol'] = 'smtp';
            $config['smtp_host'] = 'smtp.gmail.com';
            $config['smtp_port'] = '587';
            $config['_smtp_auth']=TRUE;
            $config['smtp_user'] = 'sender@gmail.com';
            $config['smtp_pass'] = 'password';
            $config['smtp_timeout'] = '60';
            $config['charset'] = 'utf-8';
            $config['wordwrap'] = TRUE;
            $config['mailtype'] = "html";

            $this->email->initialize($config);

            $this->email->from('sender@gmail.com', 'Sender');
            $this->email->to('receiver@gmail.com');

            $this->email->subject('This is my subject');
            $this->email->message('This is the content of my message');

            if ( ! $this->email->send())
            {
                show_error($this->email->print_debugger());
            }
            else
            {
                echo('DONE');
            }

但是当代码执行时,我收到以下错误

发送 AUTH LOGIN 命令失败。错误:530 5.7.0 必须先发出 STARTTLS 命令。qd9sm8462833pbb.31

我用过

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

在我的控制器的构造函数中。但我无法从本地主机发送电子邮件。发送电子邮件的解决方案是什么?我需要做哪些改变?

4

3 回答 3

4
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
于 2016-10-30T15:16:11.253 回答
1

我认为您应该在您的 Gmail 帐户中设置“启用 IMAP”选项。

它在邮件选项中。

并将您的端口更改为 465 ...

$config['smtp_port'] = '587';

$config['smtp_port'] = '465';
于 2013-08-06T21:30:27.343 回答
0

添加:

$config['smtp_crypto'] = 'tls'; // or html
于 2020-07-22T14:03:21.050 回答