CodeIgniter SMTP email message - characters replac

2019-03-18 06:35发布

I'm using the CodeIgniter email library to send emails using our Exchange server. The problem I get is that the content of the email gets messed up.

There are some words that get replaced with equal signs "=", I tried 2 different Exchange servers (they are in different locations and have no relation what so ever) and I still get the same issue. If I use any other server as an SMTP server to send emails everything works fine and the content stays intact and unchanged.

Content before sending:

Dear Customer

Please find attached a comprehensive explanation of how to get our brochure of Angola. This has been sent to you at the request of Alex.

The information has been taken from www.example.co.uk  "Company name" is one of the leading tile and marble companies in the UK. 

Content after sending it through the Microsoft Exchange:

Dear Customer

Please find attached a comprehensive explanation of how to get our brochure of A=gola. This has been sent to you at the request of Alex.

The information has been taken from www.example.co.uk  "Company name" is one of the leadi=g tile and marble companies in the UK. 

As you can see for some reason some of the "n" characters were replaced with equal signs "=" (Example: Angola > A=gola)

My email configuration:

$this->load->library('email');
$config['charset']      = 'utf-8';
$config['mailtype']     = 'html';


// SMTP
$config['protocol']     = 'smtp';
$config['smtp_host']    = 'exchange.example.com'; //ssl://
$config['smtp_user']    = 'email@example.com';
$config['smtp_pass']    = 'password';
$config['smtp_port']    = 25;

$this->email->set_newline( "\r\n" );

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

$this->email->clear();

......

$this->email->from( $frome, $fromn );
$this->email->to( $email );

$this->email->subject( $subject );
$this->email->message( $send_message );


$this->email->send();

Does anyone know why is the Microsoft exchange behaving this way? or is there some sort of setting I should use?

2条回答
成全新的幸福
2楼-- · 2019-03-18 07:01

That's odd, specially since not all the ns are transliterated and not at a specific position.

Try calling $this->email->set_crlf( "\r\n" ); as well. Look up the message details in Exchange and inspect the Content-Type and Charset / Encoding - post the raw thing here so we can inspect it.

I found this in Microsoft Knowledgebase:

Microsoft Exchange uses an enhanced character set. The default MIME character set for Microsoft Exchange is ISO 8859-1. Some gateways do not support the way this character set issues a soft return for line feeds. When this occurs, each line is terminated with an equal sign showing the line break where the gateway's line-length support ends.

查看更多
Luminary・发光体
3楼-- · 2019-03-18 07:03

I solved this (kinda) by setting $charlim = '998' in the _prep_quoted_printable function.

When I set $crlf = "\r\n" the resulting email was completely garbled for some reason. But I noticed that the = signs were appearing at regular intervals which was caused by the line length being limited to 76 characters. So increasing the max characters per line (998 is the RFC2822 limit) solves the problem, as long as you don't have really long lines.

查看更多
登录 后发表回答