Cakeemail sends email without message

Asked

Viewed 196 times

0

I’m trying to make a form to send an email. This is sent correctly and with the name of the person, who is inserted in the form, in the right place, in the email Subject. However neither the email that person inserts, nor the body of the message, appear. Only appears This email was sent using the CakePHP Framework, http://cakephp.org.. How to solve this problem?

I am using version 2.4.4 of Cakephp.

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>
  • What’s the name of this record view?

  • @Erloncharles the view is the show_contact_us.ctp.

1 answer

2


Note that by documentation, you need to set the template at the time you create the settings, and currently you use the template default, that not the same as you created and showed in your question.

So you can do something like this:

->template('show_contact_us')

This file must be in the directory app/View/Emails/html/.

  • Exactly why I asked the name of the view, this will fix the problem correctly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.