【问题标题】:CodeIgniter Email Class Failing in Specific ContextCodeIgniter 电子邮件类在特定上下文中失败
【发布时间】:2011-12-11 22:14:56
【问题描述】:

我正在使用 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)

【问题讨论】:

    标签: php email codeigniter


    【解决方案1】:

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

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

    另外,您是否有任何其他电子邮件正在发送到您可能需要的地方:clear();

    只是一个想法......

    那好吧,

    您使用什么协议?我发现 SMTP 通常比邮件更适合我。

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

    【讨论】:

    • 上面的成功信息是从 echo $this->email->print_debugger() 中检索到的,并且经过编辑的信息是正确的。
    • 我已经尝试过 mail 和 sendmail ,结果相同。我现在正在与我的房东合作,看看更新是否能解决这个问题。
    • 我知道的老话题,但我确实使用 SMTP 让事情正常进行。对于邮件无法正常工作的原因,我没有答案,但感谢您引导我使用替代解决方案。
    猜你喜欢
    • 2013-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-07
    • 2018-08-19
    • 2017-08-02
    • 2023-03-15
    • 1970-01-01
    相关资源
    最近更新 更多