views:

431

answers:

2

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

Well can we see your code snippet?

Miles Johnson
I suppose that would help, wouldn't it.
Jeff L
+1  A: 

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

Miles Johnson
This appears to have been the problem. Switching to "sendAs = 'text'" seems to have fixed it. Thanks!
Jeff L