2015-11-08 66 views
1

我有一個奇怪的問題,不知道如何解決它。我的代碼看起來完全正確,但系統嘗試連接我自己的服務器(服務器的本地主機)而不是正確的SMTP地址。CodeIgniter無法識別SMTP地址

這裏是我的代碼:

$config['protocol'] = "smtp"; 
    $config['smtp_host'] = "smtp.mandrillapp.com"; 
    $config['smtp_port'] = "587"; 
    $config['smtp_user'] = "[email protected]"; 
    $config['smtp_pass'] = "mypassword"; 
    $config['charset'] = "utf-8"; 
    $config['mailtype'] = "html"; 
    $config['newline'] = "\r\n"; 
    $CI -> email -> initialize($config); 


    $CI -> email -> from('[email protected]'); 
    $CI -> email -> reply_to('[email protected]'); 
    $CI -> email -> to($email); 
    $CI -> email -> subject('Some Topic'); 
    $CI -> email -> message('Some message'); 
    $CI -> email -> send(); 

當我運行該腳本,我得到這樣的迴應:

220-server.mydomain.com ESMTP Exim 4.86 #2 Sun, 08 Nov 2015 11:31:39 +0000 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail. 
hello: 250-server.mydomain.com Hello li1430-121.members.linode.com [85.90.227.125] 
250-SIZE 52428800 
250-8BITMIME 
250-PIPELINING 
250-AUTH PLAIN LOGIN 
250-STARTTLS 
250 HELP 

因此,它得到的登錄錯誤「的原因,而是嘗試連接錯誤的服務器。我在網上做了一個研究,但找不到任何解決方案。

在此先感謝。

回答

0

你是完全錯誤的。這意味着您使用電子郵件庫代碼的方式不正確。

  1. 不能加載此$CI ->
  2. 方法之間沒有空格像$CI -> email ->

正確的代碼是這樣的

$config['protocol'] = "smtp"; 
$config['smtp_host'] = "smtp.mandrillapp.com"; 
$config['smtp_port'] = "587"; 
$config['smtp_user'] = "[email protected]"; 
$config['smtp_pass'] = "mypassword"; 
$config['charset'] = "utf-8"; 
$config['mailtype'] = "html"; 
$config['newline'] = "\r\n"; 
$this->email->initialize($config); 


$this->email->from('[email protected]'); 
$this->email->reply_to('[email protected]'); 
$this->email->to($email); 
$this->email->subject('Some Topic'); 
$this->email->message('Some message'); 
$this->email->send(); 

Email Class in CI

+0

我使用這個代碼在助手中,所以我不能使用$ this,我必須使用$ CI。此外,這不是我的問題的解決方案,我試圖在模型中使用你的結構,但結果是一樣的。 –