CodeIgniter 电子邮件不起作用

发布于 2024-10-21 03:55:16 字数 5695 浏览 2 评论 0原文

我配置了一个可通过 localhost 访问的 SMTP 服务器。

PHP mail() 命令工作正常,我在计划任务中使用它来通过电子邮件发送备份作为附件。

如果我使用 CodeIgniter v1.7.2 电子邮件库并使用以下代码,并且 CI 调试输出显示消息已发送,但 SMTP 服务器日志显示错误发件人。

        $this->CI->load->library('email');

        $config['protocol'] = 'mail';
        $config['smtp_host'] = 'localhost';
        $config['mailtype'] = 'html';
        $config['crlf']        = "\r\n";        // CHANGED FROM DEFAULTS
        $config['newline']     = "\r\n";        // CHANGED FROM DEFAULTS

        $this->CI->email->initialize($config);

        $this->CI->email->from('[email protected]');
        $this->CI->email->to($_POST['email']); 

        $this->CI->email->subject('Password Reset');
        $this->CI->email->message('Testing the email class. <a href="http://www.google.co.uk">test</a>');   

        $this->CI->email->send();

这是来自 PHP 邮件的 2 条消息的日志(将域更改为hiddendomain1/2)

03/10/11 16:26:39   ME-I0107: [496] Relay Granted: Sender IP (127.0.0.1) is within an authorized IP range.
03/10/11 16:26:39   ME-I0149: [496] AFAB1A79683B434EAD6A415C5DAA7D52.MAI was received successfully and delivery thread was initiated
03/10/11 16:26:39   ME-I0074: [496] (Debug) End of conversation
03/10/11 16:26:39   ME-I0107: [552] Relay Granted: Sender IP (127.0.0.1) is within an authorized IP range.
03/10/11 16:26:39   ME-I0149: [552] 16B8D83CD6B040489608FCE5E9C3A177.MAI was received successfully and delivery thread was initiated
03/10/11 16:26:39   ME-I0074: [552] (Debug) End of conversation
03/10/11 16:26:40   ME-I0018: [8F72D521DC554A13AA1E0973090A75B9.MAI] Outbound message from ([SMTP:[email protected]]) requeued as [CC32D29A0BA34D9496B1602A8150B7EE.MAI] to the target domain [hiddendomain2.com]
03/10/11 16:26:40   ME-I0123: Domain [hiddendomain2.com] has MX list [mailserver.hiddendomain2.com]
03/10/11 16:26:40   ME-I0026: [CC32D29A0BA34D9496B1602A8150B7EE.MAI] Sending message
03/10/11 16:26:40   ME-I0018: [9D2654AE500442E4A90DDFD75B98C0B5.MAI] Outbound message from ([SMTP:[email protected]]) requeued as [90EF8F85B103431FB14A32F535AFFFFD.MAI] to the target domain [hiddendomain2.com]
03/10/11 16:26:40   ME-I0123: Domain [hiddendomain2.com] has MX list [mailserver.hiddendomain2.com]
03/10/11 16:26:40   ME-I0026: [90EF8F85B103431FB14A32F535AFFFFD.MAI] Sending message
03/10/11 16:26:40   ME-I0049: [CC32D29A0BA34D9496B1602A8150B7EE.MAI] Send Completed Successfully
03/10/11 16:26:41   ME-I0049: [90EF8F85B103431FB14A32F535AFFFFD.MAI] Send Completed Successfully

这是通过 CodeIgniter 发送后的日志,您可以看到 CI 电子邮件库添加了 < char 到发件人地址,任何人都可以帮助告诉我为什么吗?这是 CI 的 bug 吗?

03/10/11 16:26:42   ME-I0107: [568] Relay Granted: Sender IP (127.0.0.1) is within an authorized IP range.
03/10/11 16:26:42   ME-I0149: [568] B1D7A0FCDF44403291E8EAD33F5F144F.MAI was received successfully and delivery thread was initiated
03/10/11 16:26:42   ME-I0074: [568] (Debug) End of conversation
03/10/11 16:26:42   ME-I0018: [38DFE013802046528FAC7823871869CC.MAI] Outbound message from ([SMTP:<[email protected]]) requeued as [AC83949E463246DDBD022BBF355D4606.MAI] to the target domain [hiddendomain2.com]
03/10/11 16:26:42   ME-I0123: Domain [hiddendomain2.com] has MX list [mailserver.hiddendomain2.com]
03/10/11 16:26:42   ME-I0026: [AC83949E463246DDBD022BBF355D4606.MAI] Sending message
03/10/11 16:26:42   ME-IXXXX: [AC83949E463246DDBD022BBF355D4606.MAI] Remote server returned a response indicating a permanent error. Server Response: (501 Bad sender address syntax**)
03/10/11 16:26:42   ME-E0036: [AC83949E463246DDBD022BBF355D4606.MAI] MAIL FROM command Failed.
03/10/11 16:26:42   ME-E0008: [AC83949E463246DDBD022BBF355D4606.MAI] Outbound, could not send the command to the server (error 10038).
03/10/11 16:26:42   ME-E0060: [AC83949E463246DDBD022BBF355D4606.MAI] - Message could not be delivered to target domain (hiddendomain2.com). Message returned to Sender.
03/10/11 16:26:43   ME-I0119: Domain [hiddendomain1.com] has used local loopback address [127.0.0.1] because it is hosted locally.
03/10/11 16:26:43   ME-I0026: [AC83949E463246DDBD022BBF355D4606.MAI] Sending message
03/10/11 16:26:43   ME-I0102: [572] Address ([SMTP:<[email protected]]) is to be delivered to Catch-All address.
03/10/11 16:26:43   ME-I0149: [572] CAEFBF802B8646DB99B4D2401571AE3E.MAI was received successfully and delivery thread was initiated
03/10/11 16:26:43   ME-I0049: [AC83949E463246DDBD022BBF355D4606.MAI] Send Completed Successfully
03/10/11 16:26:43   ME-I0074: [572] (Debug) End of conversation
03/10/11 16:26:43   ME-I0132: Catch-All Message rendered for CAEFBF802B8646DB99B4D2401571AE3E.MAI

看起来这个 bug 是在这里报告的,但由于 SMTP 服务器的问题而被回避,但问题似乎确实是 CI 库的兼容性问题:http://codeigniter.com/forums/viewthread/114030/

我非常确定这是 CI 的问题,因为 PHP 邮件工作正常。有人能证实吗?因为如果没有的话我需要更改 CI 使用的脚本。我可以提供任何日志/详细信息

I configured an SMTP server accessible via localhost.

PHP mail() command works fine, I use it in scheduled tasks to email backups as attachments.

If I use CodeIgniter v1.7.2 email library using the following code, and the CI debug output says the message is sent, but the SMTP server logs show Bad Sender.

        $this->CI->load->library('email');

        $config['protocol'] = 'mail';
        $config['smtp_host'] = 'localhost';
        $config['mailtype'] = 'html';
        $config['crlf']        = "\r\n";        // CHANGED FROM DEFAULTS
        $config['newline']     = "\r\n";        // CHANGED FROM DEFAULTS

        $this->CI->email->initialize($config);

        $this->CI->email->from('[email protected]');
        $this->CI->email->to($_POST['email']); 

        $this->CI->email->subject('Password Reset');
        $this->CI->email->message('Testing the email class. <a href="http://www.google.co.uk">test</a>');   

        $this->CI->email->send();

This is the log from PHP mail for 2 messages (changed domains to hiddendomain1/2)

03/10/11 16:26:39   ME-I0107: [496] Relay Granted: Sender IP (127.0.0.1) is within an authorized IP range.
03/10/11 16:26:39   ME-I0149: [496] AFAB1A79683B434EAD6A415C5DAA7D52.MAI was received successfully and delivery thread was initiated
03/10/11 16:26:39   ME-I0074: [496] (Debug) End of conversation
03/10/11 16:26:39   ME-I0107: [552] Relay Granted: Sender IP (127.0.0.1) is within an authorized IP range.
03/10/11 16:26:39   ME-I0149: [552] 16B8D83CD6B040489608FCE5E9C3A177.MAI was received successfully and delivery thread was initiated
03/10/11 16:26:39   ME-I0074: [552] (Debug) End of conversation
03/10/11 16:26:40   ME-I0018: [8F72D521DC554A13AA1E0973090A75B9.MAI] Outbound message from ([SMTP:[email protected]]) requeued as [CC32D29A0BA34D9496B1602A8150B7EE.MAI] to the target domain [hiddendomain2.com]
03/10/11 16:26:40   ME-I0123: Domain [hiddendomain2.com] has MX list [mailserver.hiddendomain2.com]
03/10/11 16:26:40   ME-I0026: [CC32D29A0BA34D9496B1602A8150B7EE.MAI] Sending message
03/10/11 16:26:40   ME-I0018: [9D2654AE500442E4A90DDFD75B98C0B5.MAI] Outbound message from ([SMTP:[email protected]]) requeued as [90EF8F85B103431FB14A32F535AFFFFD.MAI] to the target domain [hiddendomain2.com]
03/10/11 16:26:40   ME-I0123: Domain [hiddendomain2.com] has MX list [mailserver.hiddendomain2.com]
03/10/11 16:26:40   ME-I0026: [90EF8F85B103431FB14A32F535AFFFFD.MAI] Sending message
03/10/11 16:26:40   ME-I0049: [CC32D29A0BA34D9496B1602A8150B7EE.MAI] Send Completed Successfully
03/10/11 16:26:41   ME-I0049: [90EF8F85B103431FB14A32F535AFFFFD.MAI] Send Completed Successfully

This is the log after sending via CodeIgniter, as you can see the CI email library is adding the < char to the From address, can any help tell me why? is this is bug with CI?

03/10/11 16:26:42   ME-I0107: [568] Relay Granted: Sender IP (127.0.0.1) is within an authorized IP range.
03/10/11 16:26:42   ME-I0149: [568] B1D7A0FCDF44403291E8EAD33F5F144F.MAI was received successfully and delivery thread was initiated
03/10/11 16:26:42   ME-I0074: [568] (Debug) End of conversation
03/10/11 16:26:42   ME-I0018: [38DFE013802046528FAC7823871869CC.MAI] Outbound message from ([SMTP:<[email protected]]) requeued as [AC83949E463246DDBD022BBF355D4606.MAI] to the target domain [hiddendomain2.com]
03/10/11 16:26:42   ME-I0123: Domain [hiddendomain2.com] has MX list [mailserver.hiddendomain2.com]
03/10/11 16:26:42   ME-I0026: [AC83949E463246DDBD022BBF355D4606.MAI] Sending message
03/10/11 16:26:42   ME-IXXXX: [AC83949E463246DDBD022BBF355D4606.MAI] Remote server returned a response indicating a permanent error. Server Response: (501 Bad sender address syntax**)
03/10/11 16:26:42   ME-E0036: [AC83949E463246DDBD022BBF355D4606.MAI] MAIL FROM command Failed.
03/10/11 16:26:42   ME-E0008: [AC83949E463246DDBD022BBF355D4606.MAI] Outbound, could not send the command to the server (error 10038).
03/10/11 16:26:42   ME-E0060: [AC83949E463246DDBD022BBF355D4606.MAI] - Message could not be delivered to target domain (hiddendomain2.com). Message returned to Sender.
03/10/11 16:26:43   ME-I0119: Domain [hiddendomain1.com] has used local loopback address [127.0.0.1] because it is hosted locally.
03/10/11 16:26:43   ME-I0026: [AC83949E463246DDBD022BBF355D4606.MAI] Sending message
03/10/11 16:26:43   ME-I0102: [572] Address ([SMTP:<[email protected]]) is to be delivered to Catch-All address.
03/10/11 16:26:43   ME-I0149: [572] CAEFBF802B8646DB99B4D2401571AE3E.MAI was received successfully and delivery thread was initiated
03/10/11 16:26:43   ME-I0049: [AC83949E463246DDBD022BBF355D4606.MAI] Send Completed Successfully
03/10/11 16:26:43   ME-I0074: [572] (Debug) End of conversation
03/10/11 16:26:43   ME-I0132: Catch-All Message rendered for CAEFBF802B8646DB99B4D2401571AE3E.MAI

It looks the bug was reported here but shunned off as a problem with the SMTP server but it seems the problem is indeed a compatibility issues with the CI lib: http://codeigniter.com/forums/viewthread/114030/

I am pretty damn sure that this is a problem with CI as PHP mail works fine. Can anyone confirm? because if not I need to change the script I use with CI. I can provide any logs / details

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

两个我 2024-10-28 03:55:16

我曾经遇到过同样的问题,我在代码中做了这个更改:

$config['protocol'] = 'smtp';
$config['validate'] = 'FALSE';

我希望这对你有用

I used to have the same problem, I did this change in my code:

$config['protocol'] = 'smtp';
$config['validate'] = 'FALSE';

I hope that works for you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文