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

发布于 2024-08-05 12:33:39 字数 1476 浏览 3 评论 0原文

我正在为一个组织编写一个小型 CakePHP 应用程序,其中包含一个简单的联系表单,该表单接受电子邮件地址、主题和消息,并将消息通过电子邮件发送到该地址。

一切似乎都工作正常,发送给我自己或组织中任何人的任何电子邮件都可以正常到达,除非他们通过 POP 访问邮件(大多数人都是这样做的)。在这种情况下,电子邮件到达时带有主题,但正文为空。但是,如果通过网络邮件客户端读取邮件,则正文显示得很好。

还有其他人遇到过这个问题吗?这是 CakePHP、电子邮件标头的问题,还是我应该与托管公司联系?我的代码直接基于CakePHP 文档中给出的示例

这是接收请求数据并发送电子邮件的控制器操作:

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'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.

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. 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.

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? My code is based directly on the example given in the CakePHP documentation.

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'));
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只有影子陪我不离不弃 2024-08-12 12:33:39

我认为问题是你不能使用 send() 来发送 html/文本消息。当你将消息传递给发送基本文本消息的send()时,如果要发送html消息,则必须将数据设置到模板中。

http://book.cakephp.org/view/ 269/发送基本消息#Controller-273

I think the problem is that you cant use send() to send both an html/text message. 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.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文