\ r \ n不起作用,但\ r \ n \ r \ n起作用 [英] \r\n not working but \r\n\r\n works

查看:449
本文介绍了\ r \ n不起作用,但\ r \ n \ r \ n起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过CodeIgniter的电子邮件-> send()发送电子邮件.我遇到了我无法弄清的异常情况.

I am sending an email via CodeIgniter's email->send(). I have come across an anomaly that I cannot figure out.

"\ r \ n"在电子邮件的特定部分中不起作用.但是,如果我将"\ r \ n"切换为"\ r \ n \ r \ n",则可以使用.通过工作,我的意思是,它增加了预期的2个换行符.

"\r\n" is not working in a certain section of the email. However if I switch "\r\n" to "\r\n\r\n" it works. By works I mean, it adds the 2 line breaks expected.

问题区域在底部.

$order  = $this->ordersclass->getOrder( $order_id );
$quantity   = $order['no_codes'];
$client = $this->clientclass->getClient( $order['client_id'] );
$multi_d    = $this->session->userdata('multi-use-codes-d');
$multi_t    = $this->session->userdata('multi-use-codes-t');

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

$to         = $client['client_email'];
$subject    = 'Personal Resiliency Builder Order';
$from       = 'accounts@resiliencybuilder.com.au';

$message  = "TAX INVOICE\r\n\r\n";
$message .= "Client Name: ". $client['client_name']."\r\n";
$message .= "Invoice Number: ".$order['order_id']."\r\n";
$message .= "Invoice Date: ".$order['order_timestamp']."\r\n\r\n";

$message .= "TOTAL AMOUNT PAYABLE:     $".number_format($order['order_amount'],2)."\r\n";
$message .= "GST ON SERVICES:          $".number_format(($order['order_amount']/110)*10,2)."\r\n\r\n";

$message .= "ACCOUNT PAID IN FULL VIA CREDIT CARD\r\n\r\n";
$message .= "=============================================================\r\n";

$message .= "DESCRIPTION OF SERVICES\r\n\r\n";

$message .= "Code List Name: ".$this->session->userdata('codelistname') . "\r\n";
$message .= "Quantity: ".$quantity ."\r\n";
$message .= "Single-use Developmental Reports Purchased: ".$order['no_codes_d']."\r\n";
$message .= "Single-use Thriving Reports Purchased: ".$order['no_codes_t']."\r\n";

最后2个$message变量是问题所在.

The last 2 $message variables are the problem.

电子邮件看起来像这样:

The email looks like this:

应付总金额:$ 1,771.00

TOTAL AMOUNT PAYABLE: $1,771.00

商品服务税:$ 161.00

GST ON SERVICES: $161.00

通过信用卡全额支付的帐户

ACCOUNT PAID IN FULL VIA CREDIT CARD

================================================ =============

=============================================================

服务描述

代码列表名称:fggdgfdgfd

Code List Name: fggdgfdgfd

数量:12

购买的单次使用发展报告:7次单次使用兴旺发展 购买的报告:5

Single-use Developmental Reports Purchased: 7 Single-use Thriving Reports Purchased: 5

购买的多用途发展报告:5 购买的多用途繁荣报告:5

Multi-use Developmental Reports Purchased: 5 Multi-use Thriving Reports Purchased: 5

已解决.现在正在寻找其背后的理解.

经过多次测试,失败的公式为:失败= X + Y:

After many tests, the formula for failure is: Failure = X + Y:

失败= X个字符长度+空格.

Failure = X character length + spaces.

此外,它表明Microsoft Outlook 20xx会出现此问题,而hotmail或gmail则不会.

In addition, it seams this problem occurs with Microsoft outlook 20xx, but not with hotmail or gmail.

示例:

$ message.="单次使用:开发报告:ddddd \ r \ n; //////失败-长度41
$ message.="单次使用:DevelopmentaldReportsd:dddddd \ r \ n; ///失败-长度41
$ message.="单次使用:dDevelopmentaldReportsd:dddddd \ r \ n; //通过-长度41
$ message.="单次使用:DevelopmentaldReportsd:dddddddddddddddddddddddddddddd \ r \ n; //通过

$message .= "Single-use: Developmental Reports : ddddd\r\n"; ////// fail - length 41
$message .= "Single-use: DevelopmentaldReportsd:dddddd\r\n"; /// fail - length 41
$message .= "Single-use:dDevelopmentaldReportsd:dddddd\r\n"; // pass - length 41
$message .= "Single-use:DevelopmentaldReportsd:dddddddddddddddddddddddddddddd\r\n"; // pass

推荐答案

注意:该答案适用于使用 CodeIgniter版本2.1.3

未在任何其他PHP框架上对此进行测试.

This is not tested on any other PHP Framework.

基于许多测试,包括更改字符长度,添加/删除空格以及使用不同的电子邮件服务进行测试:

Based on many tests via changing the character length, adding/removing spaces, and testing with different email services:

  • Outlook版本20xx
  • Hotmail
  • Gmail

可以肯定地说,CodeIgniter版本2.1.3解析消息的方式是,给定字符串长度约40个字符+ 1个空格字符+一个换行符,然后将电子邮件发送到上述所有三个电子邮件中,只有Outlook会确定换行符是额外"换行符,因此将其删除.

It is safe to conclude that CodeIgniter version 2.1.3 parses the message in such a way that given a string length around 40 characters long + 1 space character + a newline character and sending the email to all three email serves above, that only Outlook will determine that the newline character is an "Extra" newline character and therefore remove it.

可以更改Outlook设置以禁止Outlook删除多余的换行符

It is possible to change outlooks settings to disable Outlook from removing extra newline characters

如链接所示: Microsoft Outlook指南,用于禁用多余的换行符删除

简单的开发人员解决方案:

将字符串长度最大为39个字符(包括空格).

Keep your string length to a maximum 39 characters including spaces.

这篇关于\ r \ n不起作用,但\ r \ n \ r \ n起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆