2012-10-15 133 views
0

我有下面的代码无法发送AUTH LOGIN命令。错误:530 5.7.0必须发出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'] = '[email protected]'; 
      $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('[email protected]', 'Sender'); 
      $this->email->to('[email protected]'); 

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

但代码执行的时候,我收到以下错误

Failed to send AUTH LOGIN command. Error: 530 5.7.0 Must issue a STARTTLS command first. qd9sm8462833pbb.31

我已经使用

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

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

+0

它看起来像你的代码试图提供超过纯文本SMTP,不使用TLS或SSL安全连接。 –

+0

@RomanR。如何使用TLS或SSL安全连接? –

+0

我没有“如何”部分的答案(特别是'php'),但是错误消息清楚地告诉“为什么”。 –

回答

1

我想你应该在你的Gmail帐户中设置“启用IMAP”选项。

它在Mail选项中。

,改变你的端口465 ...

$配置[ 'SMTP_PORT'] = '587';

$配置[ 'SMTP_PORT'] = '465';

好运...

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

欢迎来到Stack Overflow Ariel!请给你的答案添加一个描述,解释这是如何解决这个问题的!你可以阅读一些更多的信息,如何破解堆栈溢出的答案:http://stackoverflow.com/help/how-to-answer – dirtydanee

+0

虽然这段代码可以解决问题,但它不能解释为什么或如何回答这个问题。请[请为您的代码添加解释](// meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers),因为这确实有助于提高帖子的质量。请记住,您将来会为读者回答问题,而这些人可能不知道您的代码建议的原因。 **举报人/评论者:** [仅限代码解答,例如downvote,请勿删除!](// meta.stackoverflow.com/a/260413/2747593) –

相关问题