2011-10-20 40 views
2

我正在使用CodeIgniter的Tank Auth庫。當用戶註冊時,系統向他們發送電子郵件激活。這在我的本地設置上正常工作,但在實時服務器上電子郵件沒有被髮送(或者至少永遠不會到達)。從其他地方自動發送的電子郵件 - 我編寫的控制器 - 使用CodeIgniter的電子郵件類將按預期交付。CodeIgniter電子郵件類別在特定上下文中失敗

例如,下面的代碼在我的控制器之一是本地正常工作和生活的服務器上:

$message = $this->load->view('email/email', $this->data, true); 

$this->email->clear(); 
$this->email->to  ($send_to); 
$this->email->reply_to ($reply_to); 
$this->email->from  ($from); 
$this->email->subject ($subject); 
$this->email->message ($message); 
$this->email->send  (); 

這段代碼在坦克驗證發送我的本地設置電子郵件,但沒有這樣做的直播服務器:

$this->load->library ('email'); 
$this->email->from  ($this->config->item('from_email'), $this->config->item('site_title')); 
$this->email->reply_to ($this->config->item('reply_email'), $this->config->item('site_title')); 
$this->email->to  ($email); 
$this->email->subject (sprintf($this->lang->line('auth_subject_' . $type), $this->config->item('site_title'))); 
$this->email->message ($this->load->view('email/' . $type . '-html', $data, TRUE)); 
$this->email->send  (); 

但是,它似乎系統認爲它是發送電子郵件:

Your message has been successfully sent using the following protocol: mail 

User-Agent: CodeIgniter 
Date: Thu, 20 Oct 2011 12:30:28 -0400 
From: "[redacted]" 
Return-Path: 
Reply-To: "[redacted]" 
X-Sender: [redacted] 
X-Mailer: CodeIgniter 
X-Priority: 3 (Normal) 
Message-ID: <[email protected][redacted]> 
Mime-Version: 1.0 
Content-Type: multipart/alternative; boundary="B_ALT_4ea04ca449ef3" 

[message content] 

與以下工作更換笨郵件的東西無處不在:

$hash   = md5(time()); 
$mime_boundary = "==Multipart_Boundary_x".$hash."x"; 
$headers  = "From: $email->from \n" . 
       "Reply-To: $email->reply_to \n" . 
       "MIME-Version: 1.0 \n" . 
       "Content-Type: multipart/mixed; \n" . 
       " boundary=\"{$mime_boundary}\""; 
$body   = "This is a multi-part message in MIME format.\n\n" . 
       "--{$mime_boundary}\n" . 
       "Content-Type:text/html; charset=\"utf-8\"\n" . 
       "Content-Transfer-Encoding: 8bit\n\n".$email->message."\n\n"; 

mail($email->to, $email->subject, $body, $headers); 

所以,很明顯,我有一個可行的變通,但我真的想知道是什麼原因造成這樣一個具體的故障都爲我的未來的自己和對於其他可能會遇到同樣問題的人來說。

我確實找到了this question which seems to be about the same or a related problem,但沒有答案。

UPDATE:我的主人戳了一圈,發現與此問題相關的以下錯誤:

Oct 20 17:16:25 host qmail-scanner[26428]: Policy:Bad_MIME:RC:1(127.0.0.1) 

回答

1

你確認每個值通過了坦克驗證電子郵件是否正確?

此外,send()返回false嗎?另外,你是否還有其他郵件在你需要的地方發送:clear();

只是一個想法...

好吧,那

什麼協議是您使用?我發現SMTP通常比郵件更適合我。

SMTP(或軟件更新)也可以修復您的'政策:Bad_MIME'問題。請參閱: http://www.atomicorp.com/forum/viewtopic.php?f=2&t=4337

+0

上述成功消息正在從echo $ this-> email-> print_debugger()中檢索,並且編輯的信息位是正確的。 – RARay

+0

我試過郵件和sendmail的結果相同。我現在正在與我的主人一起工作,看看更新是否能解決這個問題。 – RARay

+0

老主題我知道,但我確實使用SMTP使事情工作。我對郵件無法正常工作的答案沒有答案,但感謝您指導我選擇另一種解決方案。 – RARay