Here we go with a contact form for last 1.2.0.5427alpha:
--------------------------------------------------------------------------------
CONTROLLER: contacts_controller.php
--------------------------------------------------------------------------------
<?php
class ContactsController extends AppController
{
var $name = "Contacts";
var $uses = 'Contact';
var $components = array('Email');
//-----------------------------------------
function index(){
$this->set('title_for_layout', 'Contatti');
if(isset($this->data)) {
if($this->Contact->create($this->data) && $this->Contact-
>validates()){
//send e-mail
$this->_sendMail();
}
else{
$this->Session->setFlash('correggi gli errori
sottostanti');
//$this->redirect('/contacts');
}
}
}
function _sendMail() {
$senderEmail = $this->data['Contact']['e-mail'];
$this->Email->layout = 'email';
$this->Email->to = '[EMAIL PROTECTED]';
$this->Email->subject = $this->data['Contact']['oggetto'];
$this->Email->from = $senderEmail;
$this->Email->template = 'text';
//Send as 'html', 'text' or 'both' (default is 'text')
$this->Email->sendAs = 'text';
//Set view variables as normal
$this->set('nome', ucfirst($this->data['Contact']['nome']));
$this->set('cognome', ucfirst($this->data['Contact']
['cognome']));
$this->set('email', $senderEmail);
$this->set('oggetto', $this->data['Contact']['oggetto']);
$this->set('messaggio', $this->data['Contact']['messaggio']);
//Do not pass any args to send()
if ( $this->Email->send() ) {
$this->Session->setFlash('La tua e-mail è stata
spedita con successo');
$this->redirect('/');
exit;
} else {
$this->Session->setFlash("Ci sono stati dei problemi
nell'inviare l'e-mail. Ti invitiamo a riprovare");
$this->redirect('/contacts/index/');
exit;
}
}
}
?>
--------------------------------------------------------------------------------
MODEL: contact.php
--------------------------------------------------------------------------------
<?php
class Contact extends AppModel {
var $name = 'Contact';
var $useTable = false;
var $validate = array(
'nome' => array('required' => VALID_NOT_EMPTY),
'cognome' => array('required' => VALID_NOT_EMPTY),
'e-mail' => array('required' => VALID_NOT_EMPTY,
'validEmail'=>VALID_EMAIL),
'oggetto' => array('required' => VALID_NOT_EMPTY),
'messaggio' => array('required' =>
VALID_NOT_EMPTY),
);
}
?>
-----------------------------------------------------------------------
E_MAIL TEMPLATE: views/layouts/email/text/email.ctp
-----------------------------------------------------------------------
-------------------------------------------------------------------
EMAIL FROM IntellighenziaProject.it
-------------------------------------------------------------------
FROM : <?=$cognome.' '.$nome?>
E-MAIL : <?=$email?>
SUBJECT: <?=$oggetto?>
-------------------------------------------------------------------
MESSAGE:
-------------------------------------------------------------------
<?=$messaggio?>
-------------------------------------------------------------------
Hope this helps.
Dan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---