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 );
所以,显然我有一个可行的解决方法,但我真的很想知道是什么导致了我未来的自己和对于其他可能遇到困难的人同样的问题。
我确实找到了 这个问题似乎与相同或相关的问题有关但没有答案。
更新:我的主机四处查看并发现与此问题相关的以下错误:
Oct 20 17:16:25 host qmail-scanner[26428]: Policy:Bad_MIME:RC:1(127.0.0.1)
I am using the Tank Auth library for CodeIgniter. When a user is registered, the system sends them an email activation. This is working properly on my local setup, but on the live server the email is not being sent (or at least it never arrives). Emails that are automatically sent from other places - controllers that I write - using CodeIgniter's email class are being delivered as expected.
For example, this code in one of my controllers is working properly locally and on the live server:
$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 code in Tank Auth sends an email on my local setup, but fails to do so on the live server:
$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 ();
However, it does appear that the system thinks it is sending the email:
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]
Replacing the CodeIgniter mail stuff with the following works everywhere:
$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 );
So, obviously I have a viable work-around, but I would really like to know what is causing such a specific failure both for my future self and for others who might be coming up against the same issue.
I did find this question which seems to be about the same or a related problem but there is no answer.
UPDATE: My host poked around and found the following error related to this problem:
Oct 20 17:16:25 host qmail-scanner[26428]: Policy:Bad_MIME:RC:1(127.0.0.1)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,
您使用什么协议?我发现 SMTP 通常比邮件更适合我。
SMTP(或软件更新)也可以解决您的“Policy:Bad_MIME”问题。看:
http://www.atomicorp.com/forum/viewtopic.php ?f=2&t=4337
OK then,
What protocol are you using? I've found that SMTP often works better for me than mail.
SMTP (or a software update) could also fix your 'Policy:Bad_MIME' issue. See:
http://www.atomicorp.com/forum/viewtopic.php?f=2&t=4337