CodeIgniter电子邮件类在特定上下文中失败

时间:2011-10-20 15:53:28

标签: php email codeigniter

我正在为CodeIgniter使用Tank Auth库。当用户注册时,系统会向他们发送电子邮件激活。这在我的本地设置上正常工作,但在实时服务器上没有发送电子邮件(或者至少它永远不会到达)。使用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      ();

Tank Auth中的此代码在我的本地设置上发送电子邮件,但在实时服务器上无法执行此操作:

$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: <4ea04ca449b0d@[redacted]>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_4ea04ca449ef3"

[message content]

使用以下方法替换CodeIgniter邮件:

$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,但没有答案。

更新:我的主持人四处寻找并发现以下与此问题相关的错误:

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

1 个答案:

答案 0 :(得分:1)

  

您是否验证了Tank Auth传递给电子邮件的每个值是否正确?

     

另外,send()是否会返回false?

     

此外,您是否还有其他可能需要发送的电子邮件:clear();

     

只是一个想法...

好的,

您使用的是哪种协议?我发现SMTP通常比邮件更适合我。

SMTP(或软件更新)也可以解决您的“政策:Bad_MIME”问题。看到: http://www.atomicorp.com/forum/viewtopic.php?f=2&t=4337