【发布时间】:2014-04-15 11:20:18
【问题描述】:
当我使用 PHP 邮件命令时,电子邮件被正确发送(屏幕截图中当前会话中的用户 web2),但是使用 CodeIgniter 电子邮件库时不发送邮件(屏幕截图中当前会话中的用户 [null])。请有人帮忙解决这个问题,我在下面提供了尽可能多的信息,谢谢。
应用程序/配置/email.php
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'localhost';
$config['smtp_user'] = 'Administrator';
$config['smtp_pass'] = 'xxx';
$config['smtp_port'] = '25';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
应用程序/模型/master.php
$site_config = $this->site_config();
// $this->load->library('email');
// $this->email->from($site_config['email_from'], $site_config['name']);
// $this->email->to($site_config['email_to']);
// $this->email->subject($subject);
// $this->email->message($html);
// if ($text==''){
// $text = $html;
// }
// $this->email->set_alt_message($text);
$headers = 'From: '.$site_config['email_from'] . "\r\n" .
'Reply-To: '.$site_config['email_from'] . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if (mail($site_config['email_to'], $subject, $text,$headers)){
// if ($this->email->send()){
return 1;
}else{
return false;
}
php.ini
[mail function]
SMTP = localhost
smtp_port = 25
mail.add_x_header = On
IIS SMTP
Relay Restrictions
Only the list below
Granted 127.0.0.1
Granted localhost
Granted servername
[x] Allow all computers which successfully authenticate to rellay, regardless of the list above.
Outbound Security
Basic authentication
User name: xxx
Password: xxx
Advanced Delivery
Smart host: mail.external_host.com
C:\WINDOWS\system32\LogFiles\SMTPSVC1
CodeIgniter(不工作 - 手动终止活动连接)
#Software: Microsoft Internet Information Services 6.0
#Version: 1.0
#Date: 2014-04-15 12:32:21
#Fields: date time c-ip cs-username s-sitename s-computername s-ip s-port cs-method cs-uri-stem cs-uri-query sc-status sc-win32-status sc-bytes cs-bytes time-taken cs-version cs-host cs(User-Agent) cs(Cookie) cs(Referer)
2014-04-15 12:32:21 127.0.0.1 - SMTPSVC1 WEB2 127.0.0.1 0 QUIT - - 240 21500 159 4 21500 SMTP - - - -
PHP 邮件(工作)
#Software: Microsoft Internet Information Services 6.0
#Version: 1.0
#Date: 2014-04-15 12:31:06
#Fields: date time c-ip cs-username s-sitename s-computername s-ip s-port cs-method cs-uri-stem cs-uri-query sc-status sc-win32-status sc-bytes cs-bytes time-taken cs-version cs-host cs(User-Agent) cs(Cookie) cs(Referer)
2014-04-15 12:31:06 127.0.0.1 web2 SMTPSVC1 WEB2 127.0.0.1 0 HELO - +web2 250 0 28 9 0 SMTP - - - -
2014-04-15 12:31:06 127.0.0.1 web2 SMTPSVC1 WEB2 127.0.0.1 0 MAIL - +FROM:<from@address_removed.com> 250 0 45 32 0 SMTP - - - -
2014-04-15 12:31:06 127.0.0.1 web2 SMTPSVC1 WEB2 127.0.0.1 0 RCPT - +TO:<to@address_removed.com> 250 0 41 38 0 SMTP - - - -
2014-04-15 12:31:06 127.0.0.1 web2 SMTPSVC1 WEB2 127.0.0.1 0 DATA - <WEB2FRaqbC8wSA1XvpF0000000b@web2> 250 0 117 663 31 SMTP - - - -
2014-04-15 12:31:06 127.0.0.1 web2 SMTPSVC1 WEB2 127.0.0.1 0 QUIT - web2 240 31 53 4 0 SMTP - - - -
2014-04-15 12:31:06 y.y.y.y OutboundConnectionResponse SMTPSVC1 WEB2 - 25 - - 220+mail.external_host.com+ESMTP+Sendmail+8.14.2/8.14.2/;+Tue,+15+Apr+2014+13:31:13++0100+(BST) 0 0 90 0 47 SMTP - - - -
2014-04-15 12:31:06 y.y.y.y OutboundConnectionCommand SMTPSVC1 WEB2 - 25 EHLO - web2 0 0 4 0 47 SMTP - - - -
2014-04-15 12:31:06 y.y.y.y OutboundConnectionResponse SMTPSVC1 WEB2 - 25 - - 250-mail.external_host.com+Hello+local.internal_host+[x.x.x.x]+(may+be+forged),+pleased+to+meet+you 0 0 112 0 78 SMTP - - - -
2014-04-15 12:31:06 y.y.y.y OutboundConnectionCommand SMTPSVC1 WEB2 - 25 AUTH - - 0 0 4 0 78 SMTP - - - -
2014-04-15 12:31:06 y.y.y.y OutboundConnectionResponse SMTPSVC1 WEB2 - 25 - - 334+UGFzc3dvcmQ6 0 0 16 0 110 SMTP - - - -
2014-04-15 12:31:06 y.y.y.y OutboundConnectionResponse SMTPSVC1 WEB2 - 25 - - 235+2.0.0+OK+Authenticated 0 0 26 0 141 SMTP - - - -
2014-04-15 12:31:06 y.y.y.y OutboundConnectionCommand SMTPSVC1 WEB2 - 25 MAIL - FROM:<from@address_removed.com>+SIZE=944 0 0 4 0 141 SMTP - - - -
2014-04-15 12:31:06 y.y.y.y OutboundConnectionResponse SMTPSVC1 WEB2 - 25 - - 250+2.1.0+<from@address_removed.com>...+Sender+ok 0 0 45 0 157 SMTP - - - -
2014-04-15 12:31:06 y.y.y.y OutboundConnectionCommand SMTPSVC1 WEB2 - 25 RCPT - TO:<to@address_removed.com> 0 0 4 0 157 SMTP - - - -
2014-04-15 12:31:06 y.y.y.y OutboundConnectionResponse SMTPSVC1 WEB2 - 25 - - 250+2.1.5+<to@address_removed.com>...+Recipient+ok 0 0 56 0 188 SMTP - - - -
2014-04-15 12:31:06 y.y.y.y OutboundConnectionCommand SMTPSVC1 WEB2 - 25 DATA - - 0 0 4 0 188 SMTP - - - -
2014-04-15 12:31:06 y.y.y.y OutboundConnectionResponse SMTPSVC1 WEB2 - 25 - - 354+Enter+mail,+end+with+"."+on+a+line+by+itself 0 0 48 0 219 SMTP - - - -
2014-04-15 12:31:06 y.y.y.y OutboundConnectionResponse SMTPSVC1 WEB2 - 25 - - 250+2.0.0+s3FCVDTZ085408+Message+accepted+for+delivery 0 0 54 0 547 SMTP - - - -
2014-04-15 12:31:06 y.y.y.y OutboundConnectionCommand SMTPSVC1 WEB2 - 25 QUIT - - 0 0 4 0 547 SMTP - - - -
2014-04-15 12:31:06 y.y.y.y OutboundConnectionResponse SMTPSVC1 WEB2 - 25 - - 221+2.0.0+mail.external_host.com+closing+connection 0 0 46 0 578 SMTP - - - -
print_debugger(手动终止连接时)
A PHP Error was encountered
Severity: Notice
Message: fwrite(): send of 39 bytes failed with errno=10053 An established connection was aborted by the software in your host machine.
Filename: libraries/Email.php
Line Number: 1816
A PHP Error was encountered
Severity: Notice
Message: fwrite(): send of 5 bytes failed with errno=10053 An established connection was aborted by the software in your host machine.
Filename: libraries/Email.php
Line Number: 1816
A PHP Error was encountered
Severity: Notice
Message: fwrite(): send of 890 bytes failed with errno=10053 An established connection was aborted by the software in your host machine.
Filename: libraries/Email.php
Line Number: 1816
A PHP Error was encountered
Severity: Notice
Message: fwrite(): send of 2 bytes failed with errno=10053 An established connection was aborted by the software in your host machine.
Filename: libraries/Email.php
Line Number: 1816
y220 web2 Microsoft ESMTP MAIL Service, Version: 6.0.3790.3959 ready at Tue, 15 Apr 2014 14:08:56 +0100
hello:
The following SMTP error was encountered:
from:
The following SMTP error was encountered:
Unable to send data: RCPT TO:
to:
The following SMTP error was encountered:
Unable to send data: DATA
data:
The following SMTP error was encountered:
Unable to send data: User-Agent: CodeIgniter Date: Tue, 15 Apr 2014 14:08:56 +0100 From: "From_Name_Here" Return-Path: To: to@address_removed.com Subject: =?utf-8?Q?Contact_Form?= Reply-To: "noreply@address_removed.com" X-Sender: noreply@address_removed.com X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: <534d2f68ddae0@address_removed.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="B_ALT_534d2f68ddae0" This is a multi-part message in MIME format. Your email application may not support this format. --B_ALT_534d2f68ddae0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit This is a message --B_ALT_534d2f68ddae0 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable This is a message --B_ALT_534d2f68ddae0--
Unable to send data: .
The following SMTP error was encountered:
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Tue, 15 Apr 2014 14:08:56 +0100
From: "From_Name_Here"
Return-Path:
To: to@address_removed.com
Subject: =?utf-8?Q?CLA_Contact_Form_(Brochure_Request)?=
Reply-To: "noreply@address_removed.com"
X-Sender: noreply@address_removed.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <534d2f68ddae0@address_removed.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_534d2f68ddae0"
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ALT_534d2f68ddae0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
This is a message
--B_ALT_534d2f68ddae0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
This is a message
--B_ALT_534d2f68ddae0--
编辑:我可以确认 CodeIgniter 电子邮件库在直接连接到外部智能主机时工作,但是当连接到本地 IIS SMTP 时,它无法成功连接到中继。我不知道为什么会这样,因为它只是一个非常基本的设置,上面提到的改动很小。
已修复:将协议更改为“邮件”系统能够连接到 IIS SMTP 本地服务器并通过智能主机成功中继电子邮件。
$config['protocol'] = 'mail';
$config['smtp_host'] = 'localhost';
$config['smtp_port'] = '25';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
【问题讨论】:
-
尽管已经完成了所有 codeigniter 配置的设置过程,您仍然使用 mail() 函数有什么原因吗?我总是使用内置在电子邮件类中的代码点火器来处理这类事情:ellislab.com/codeigniter/user-guide/libraries/email.html
-
我没有注释 php 邮件代码,因为这是我上次测试的有效代码。使用 CodeIgniter(注释代码)时,它似乎不起作用。
-
使用
$this->email->print_debugger()查看可能的错误消息。 -
@Narf:如果我不指定 SMTP 主机名,我可以让 print_debugger 显示错误。否则代码只是挂起,电子邮件库似乎创建了一个连接,但随后无法成功发送电子邮件。
标签: php codeigniter smtp