[TYPO3-mvc] fluid as an email template

Manfred Rutschmann manfred.rutschmann at revier.de
Wed Dec 1 09:12:37 CET 2010


Am Wed, 1 Dec 2010 08:56:34 +0100 schrieb Dawid Pacholczyk:

> Thank you both fior answers :)
> 
> Manfred can yuu say something more about your methiod ? Code sample ?

Yes, i can:

in your controller you have the action that is sending the email like my
one, right?:

/**
 * sends the form as contactform
 * @param Tx_RkCamperchecker_Domain_Model_Forms_Buchung $buchung
 * @return void
 */
public function sendAction(Tx_RkCamperchecker_Domain_Model_Forms_Buchung
$buchung) {
	$mail =
&t3lib_div::makeInstance("Tx_RkCamperchecker_Domain_Phpmailer_Mailer");	
	$this->view
			->assign('buchung',$buchung)
			->assign('anrede',"Guten Tag ".$buchung->getFirstname()."
".$buchung->getLastname()."")
			->assign('admin',0);
	$html = $this->view->render();
	$h2t = new Tx_RkCamperchecker_Domain_Plaintext_Convert;
	$h2t->html = $html;
	$mail->CharSet = "UTF-8";
  	$mail->AddReplyTo($this->flexformValues['contactformEmail']);
  	$mail->AddAddress($buchung->getEmail());
  	$mail->SetFrom($this->flexformValues['contactformSender']);
  	$mail->Subject = "Onlinebuchung " . $buchung->anbieter->getTitle() . " "
. $buchung->fahrzeug->getTitle();
  	$mail->AltBody = $h2t->get_text(); // optional - MsgHTML will create an
alternate automatically
  	$mail->MsgHTML($html);
  	$mail->Send();
	$this->forward('showsend', 'Bookingform', NULL
,array('buchung'=>$buchung));
}

For this action i have in /Templates/ a send.html template. There i have
some basic css styles and a table based layout. With $html =
$this->view->render() i get the whole html code. Before i assign some
objects/values to the template. In that case i have integrated the great
phpmailer class in my extension. I have some plaintext and html parts
included. With the last line i start a internal forward to a new action
named showsendAction. It`s a one liner:

	/**
	 * sends the form as contactform
	 * @param array $kontakt
	 * @return void
	 */
	public function
showsendAction(Tx_RkCamperchecker_Domain_Model_Forms_buchung $buchung) {
		$this->view->assign('buchung',$buchung);
	}
After sending the email the user see that one. It`s a very equal template,
but with some layout differences. Thats all. Very easy to use.

You can see the form on this page:
http://www.t-s-a.de/index.php?id=508&tx_rkcamperchecker_pi1[Land]=1&tx_rkcamperchecker_pi1[Fahrzeugkategorie]=6&tx_rkcamperchecker_pi1[Station]=34&tx_rkcamperchecker_pi1[Endstation]=36&tx_rkcamperchecker_pi1[Startdate]=19.12.2010&tx_rkcamperchecker_pi1[Enddate]=11.01.2011
(Use Anfrage on each car on bottom right). We have included many email
sending controllers on this extension and it works very well.

Regards Manne 


More information about the TYPO3-project-typo3v4mvc mailing list