2012-10-15 28 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) –

相關問題