I'm trying to make a form for sending an email. This is sent correctly and with the name of the person, which is inserted in the form, in the right place, in the subject of the email. However, neither the email that this person inserts, nor the body of the message, appear. Only This email was sent using the CakePHP Framework, http://cakephp.org.
appears. How do I resolve this issue?
I'm using CakePHP version 2.4.4.
Controller
<?php
class ContactsController extends AppController {
public function ShowContactUs(){
$this->layout='default';
$this->set('title_for_layout', 'Contactos');
}
public function Contact() {
$this->set('title_for_layout', 'Contactos');
$this->loadModel('Contact');
if($this->request->is('post')) {
$this->Contact->set($this->request->data);
if($this->Contact->validates(array('fieldList' => array('name','email','message')))) {
$email = new CakeEmail();
$email->config('gmail')
->from(array('[email protected]' => 'mysite'))
->to('[email protected]')
->subject('mysite.com - Contacto - ' . $this->request->data['Contact']['name'])
->emailFormat('text')
->template('default')
->viewVars(array(
'notificationType' => 'Contacto',
'message' => $this->request->data['Contact']['message'],
'name' => $this->request->data['Contact']['name'],
'email' => $this->request->data['Contact']['email'],
'title_for_layout' => 'Contacto'
))
->send();
//debug($email);
//die;
$this->request->data = null;
$this->Session->setFlash(__('Contact submitted successfully.'), 'Flash/success');
} else {
$error = $this->Notification->validationErrors;
$this->set('error', $error);
$this->Session->setFlash(__('Fill all fields'), 'Flash/warning');
}
}
}
}
?>
View ShowContactUs ()
<h3>Contactos</h3>
<style type="text/css">
div.inline { float:left;
padding-left: 2%; }
.clearBoth { clear:both; }
h3{
color:#A80000 ;
text-align: left;
}
div{text-align:justify;}
</style>
<br>
<div>
<p>Contacto Permanente: xxxxxxxxx</p>
<p>Email: xxxxxxx</p>
</div>
<div id="contact-form">
<div class="well">
<?php echo $this->Form->create('Contact', array('url' => array('controller' => 'Contacts', 'action' => 'Contact'), 'class' => 'form-horizontal')) ?>
<?php echo $this->Form->input('name', array('label' => __('Name') . ' *', 'class' => 'input-xlarge')); ?>
<?php echo $this->Form->input('email', array('label' => __('E-mail') . ' *', 'class' => 'input-xlarge')); ?>
<?php echo $this->Form->input('message', array('label' => __('Message') . ' *', 'class' => 'input-xxlarge', 'type' => 'textarea', 'rows' => 3)); ?>
<?php echo $this->Form->submit(__('Enviar'), array('class' => 'btn btn-success')) ?>
<?php echo $this->Form->end() ?>
</div>
</div>