Speed up development with full-stack environments for every branch.

Learn More

How to send email in CakePHP [sessions]

Forked from Welcome to CakePHP.

1489 Runs 8515 Views 5407 Copies
Saved

Saved

fingerout 13

fingerout
published 4 years ago

<?php
class PagesController extends AppController {

/**
 * Controller name
 *
 * @var string
 */
  public $name = 'Pages';

/**
 * This controller does not use a model
 *
 * @var array
 */
  public $uses = array();

/**
 * Displays a view
 *
 * @param mixed What page to display
 * @return void
 */
	public function display() {
    if (!empty($this->request->data)) { // form posted
      /* load CakePHP Email component */
      App::uses('CakeEmail', 'Network/Email');

      /* instantiate CakeEmail class */
      $Email = new CakeEmail();
      
      /* pass user input to function */
      $Email->from(array($this->request->data['Page']['from_email'] => $this->request->data['Page']['from_name']));
      $Email->to($this->request->data['Page']['to_email']);
      $Email->subject($this->request->data['Page']['subject']);
      $Email->send($this->request->data['Page']['message']);
      
      $this->Session->setFlash('Email sent.');
    }
    
    /* render home.ctp instead of display.ctp */
    $this->render('home');
	}
}
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).