无法发送AUTH LOGIN命令。错误:530 5.7.0必须首先发出STARTTLS命令

时间:2012-10-15 05:08:50

标签: php codeigniter smtp gmail starttls

我有以下代码

            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');

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

3 个答案:

答案 0 :(得分:2)

$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';

答案 1 :(得分:1)

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

它位于邮件选项中。

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

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

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

祝你好运......

答案 2 :(得分:0)

添加:

$config['smtp_crypto'] = 'tls'; // or html
相关问题