Cakephp发送UTF-8电子邮件和lineLength [英] Cakephp sending UTF-8 Emails and lineLength

查看:132
本文介绍了Cakephp发送UTF-8电子邮件和lineLength的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试发送带有UTF8字符的电子邮件。大多数情况下,电子邮件看起来像我所怀疑的样子,但是随机会有垃圾字符。我相信在其中一个字符的中间插入新行时会发生垃圾字符。我怀疑CakePHP的电子邮件组件是罪魁祸首,因为我读到它具有根据lineLength属性插入新行的功能。有没有什么办法解决这一问题?我正在使用CakePHP 1.3。

I'm trying to send an emails with UTF8 characters. Mostly the Email looks how I suspect, but randomly there will be garbage characters. I believe the garbage characters happen when a new line is inserted in the middle of one of the characters. I suspect CakePHP's email component is the culprit since I was reading that it has a feature to insert new lines according to its lineLength property. Is there any way to fix this? I'm using CakePHP 1.3.

$this->Email->to = $sendEmail;
$this->Email->from = empty($this->data['Contact']['email']) ? $sendEmail : $this->data['Contact']['email'];
$this->Email->subject = $subject;
$this->Email->sendAs = 'text';
$this->Email->template = 'contact'
$this->set('fields', $this->data['Contact']);
$this->Email->charset = "utf-8";
$this->Email->headerCharset = "utf-8";
return $this->Email->send();

来自电子邮件标题:

Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit


推荐答案

我发现可以通过在base64中编码电子邮件消息来解决此问题。 CakePHP的电子邮件组件本身并不执行此操作,因此我编写了一个类Email64来扩展电子邮件组件。我重写了所有包含

I discovered this problem can be solved by encoding the email message in base64. CakePHP's email component does not natively do this, so I wrote a class Email64 to extend the email component. I rewrote all functions that contained

'Content-Transfer-Encoding: 7bit';

'Content-Transfer-Encoding: base64';

然后在_mail()函数中,我替换了对php的mail函数的调用-像这样-

And then in the _mail() function, I replaced calls to php's mail function -- something like this --

return @mail($to, $this->_encode($this->subject),  $message, $header, $this->additionalParams);

对此-

return @mail($to, $this->_encode($this->subject),  rtrim(chunk_split(base64_encode($message))), $header, $this->additionalParams);

这篇关于Cakephp发送UTF-8电子邮件和lineLength的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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