CodeIgniter不会使用电子邮件库发送电子邮件

时间:2014-04-15 11:20:19

标签: php codeigniter smtp

当我使用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

SMTP Current Sessions

C:\窗口\ 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 Mail(正常工作)

#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时,它无法成功连接到中继。我不知道为什么会这样,因为它只是一个非常基本的设置,只有上面提到的最小变化。

修正:将协议更改为&#39; mail&#39;系统能够连接到IIS SMTP本地服务器,并通过智能主机成功中继电子邮件。

$config['protocol']     = 'mail';
$config['smtp_host']    = 'localhost';
$config['smtp_port']    = '25';
$config['wordwrap']     = TRUE;
$config['mailtype']     = 'html';
$config['charset']  = 'utf-8';

1 个答案:

答案 0 :(得分:0)

试试此代码。

$this->load->library('email');
    $confing =array(
    'protocol'=>'smtp',
    'smtp_host'=>"smtp.gmail.com",
    'smtp_port'=>465,
    'smtp_user'=>"sender@gmail.com",
    'smtp_pass'=>"sender Password",
    'smtp_crypto'=>'ssl',              
    'mailtype'=>'html'  
    );
    $this->email->initialize($confing);
    $this->email->set_newline("\r\n");
    $this->email->from('sender@gmail.com');
    $this->email->to(receiver@gmail.com );
    $this->email->subject('You Subject');
    $this->email->message($message);

        if(!$this->email->send()) {
                        echo json_encode(1);
        }