简体   繁体   中英

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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