简体   繁体   English

通过POP访问时,通过CakePHP发送的电子邮件显示空白消息正文

[英]E-mail sent via CakePHP shows up with blank message body when accessed via POP

I'm writing a small CakePHP application for an organization and have included a simple contact form that accepts an email address, subject, and message, and emails the message to the address. 我正在为组织编写一个小型的CakePHP应用程序,其中包括一个简单的联系表单,该表单接受电子邮件地址,主题和消息,并将该消息通过电子邮件发送给该地址。

Everything seems to work fine, and any email sent to myself or anyone at the organization arrives just fine, except if they access the message via POP , which most of them do. 一切似乎都可以正常工作,发给自己或组织中任何人的任何电子邮件都可以正常发送, 除非他们通过POP访问邮件 ,大多数情况下都是如此。 In this case, the email arrives with the subject, but the body is blank. 在这种情况下,电子邮件随主题一起到达,但正文为空白。 The body shows up just fine, however, if the message is read via the webmail client. 但是,如果通过Webmail客户端读取消息,则正文显示的很好。

Has anyone else run into this problem? 还有其他人遇到这个问题吗? Is it an issue with CakePHP, the email headers, or should I be talking to the hosting company? CakePHP,电子邮件标头是否有问题,还是应该与托管公司联系? My code is based directly on the example given in the CakePHP documentation . 我的代码直接基于CakePHP文档中给出的示例

Here's the controller action that receives the request data and sends the email: 这是接收请求数据并发送电子邮件的控制器操作:

function send() {
    if (!empty($this->data)) {
        $contact = $this->Contact->read(null, $this->data['ContactMessage']['contact_id']);
        $this->data['ContactMessage']['ip'] = $this->RequestHandler->getClientIp();
        $this->ContactMessage->create();
        if ($this->ContactMessage->save($this->data)) {
            $this->Email->to = $contact['Contact']['email'];
            $this->Email->subject = $this->data['ContactMessage']['subject'];
            $this->Email->replyTo = $this->data['ContactMessage']['email'];
            $this->Email->from = $this->data['ContactMessage']['email'];
            $this->Email->sendAs = 'both';
            $this->Email->send($this->data['ContactMessage']['message']);
            $this->redirect(array('controller' => 'contacts', 'action' => 'thanks'));
        } else {
            $this->redirect(array('controller' => 'contacts', 'action' => 'oops'));
        }
    }
}

I think the problem is that you cant use send() to send both an html/text message. 我认为问题是您不能使用send()来发送HTML /文本消息。 When you pass the message to send() that sends a basic text message, if you want to send an html message, you must set the data to the template. 当您将消息传递给发送基本文本消息的send()时,如果要发送html消息,则必须将数据设置为模板。

http://book.cakephp.org/view/269/Sending-a-basic-message#Controller-273 http://book.cakephp.org/view/269/Sending-a-basic-message#Controller-273

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM