I'm really new to CakePHP, and am trying to get a basic contact form set up for a website. I can get the form itself to appear, but when I try submitting the form, I get this error:
Fatal error: Call to undefined method EmailComponent::send() in /home/tastynib/public_html/cake/app/controllers/contacts_controller.php on line 16
Here's my controller file:
Code: Select all
<?php
class ContactsController extends AppController {
var $name = 'Contacts';
var $components = array('RequestHandler','Email');
var $helpers = array('Html','Form');
function add() {
if ($this->RequestHandler->isPost()) {
$this->Contact->set($this->data);
if ($this->Contact->validates()) {
//send email using the Email component
$this->Email->to = 'moi@salamiday.com';
$this->Email->subject = 'Salami Day contact message from ' . $this->data['Contact']['name'];
$this->Email->from = $this->data['Contact']['email'];
$this->Email->send($this->data['Contact']['message']);
// $this->redirect(array('action' => 'index'));
// $this->Session->setFlash('Your message has been sent.');
}
}
}
}
?>Code: Select all
<?php
class Contact extends AppModel {
var $name = 'Contact';
var $useTable = false; //not using the database
var $_schema = array (
'name' => array('type' => 'string', 'length' => 100),
'email' => array('type' => 'string', 'length' => 255),
'message' => array('type' => 'text', 'length' => 2000)
);
var $validate = array(
'name' => array(
'rule' => 'notEmpty',
'message' => 'Please enter your name'
),
'email' => array(
'rule' => 'email',
'message' => 'Please enter a valid email address!'
),
'message' => array(
'rule' => 'notEmpty',
'message' => 'Please enter a message'
)
);
}
?>
Code: Select all
<!-- File: /app/views/contact/add.ctp -->
<h2>Contact</h2>
<?php
$inputs = array('fieldset' => false, 'legend' => false);
echo $form->create('Contact');
echo $form->inputs();
echo $form->end('Send');
?>
I've looked all over the place for advice on this, but haven't found anything useful for me. I'm also not sure if maybe there's things I'm putting in the wrong directories just because of my lack of familiarity with Cake. In any case, I appreciate any advice anyone has to offer.
Thanks!