Re: RE : [SMARTY] How to use Smarty to make mail templates and send them
| From: | Zoran Knezevic | Date: | Fri, 14 Nov 2003 21:51:07 +0000 |
| Subject: | Re: RE : [SMARTY] How to use Smarty to make mail templates and send them | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-10541@lists.php.net to get a copy of this message | ||
OK, thanks for this peace of code.
One more quection, do you allow me to use and distribute whole or any part of it in
comercial or non-comercal products?
Anyway, I learned from that peace of code some things :)
Best regards,
Zoran
P.S. Thanks to all others who have answered me. fetch() is great thing :)
Christopher Rousseau <christopher.rousseau@rezotech.com>:
> I did have this old Email class who do that you need:
>
> ------------------
> <?php
>
> Class Email {
> var $destinataire;
> var $sujet;
> var $objet = Null;
> var $template;
>
> function Email($destinataire=Null, $sujet=Null, $objet=NULL,
> $template=Null) {
> $this->destinataire = $destinataire; // to (in french)
> $this->sujet = $sujet; // subject (in French)
> $this->objet = &$objet; // can be an array ex:
> array('myVar' => $myVar)
> $this->template = $template; // sMarty template to
> use
> }
>
> function setDestinataire($objet) {
> $this->destinataire=$objet;
> }
>
> function setSujet($objet) {
> $this->sujet=$objet;
> }
>
> function setObjet($objet) {
> $this->objet=$objet;
> }
>
> function setTemplate($objet) {
> $this->template=$objet;
> }
>
> function send() {
> global $request;
> global $globalDebug;
>
> require_once(SMARTY_DIR.'MySmarty.class.php');
> $smarty = new MySmarty();
> $smarty->template_dir =
> "/where/you/put/your/smarty/file";
> $smarty->compile_dir = '/where/you/put/your/compil/';
> $smarty->cache_dir = '/where/you/put/your/cache/';
> $smarty->debugging = false;
> // if the objet parameter is an array we assing each row to the
> Smarty Template
> if (is_array($this->objet)) {
> foreach($this->objet as $key => $value) {
> $smarty->assign($key, $value);
> }
> }
> else { // if not, we assign the 'objet' variables
> (compatibility with old way of using the class
> $smarty->assign_by_ref('objet', &$this->objet);
> }
> $mail=$smarty->fetch('Email/' . $this->template); // All
> my Email template are in the same sub directory
> $ok = mail($this->destinataire, $this->sujet, $mail,"From:
> webmaster@myDomain.net\r\n"
> ."Reply-To: webmaster@myDomain.net \r\n"
> ."X-Mailer: PHP/" . phpversion());
>
> if (!$ok)
> trigger_error("Error then sending mail", E_USER_ERROR );
> return $ok;
> }
> }
>
> ?>
> --------------------
> Ex of using it :
> $mail = new Email($email);
> $mail->setSujet(Subject of the mail');
> $mail->setObjet(array('name'=>'Mr X Y', 'otherVar' =>
> $overVar);
> $mail->setTemplate('preInscritLocation.tpl');
> $mail->send();
> --------------------------
>
> I have add some comment. But ask if you need more info...
>
> Christopher ROUSSEAU
>
> Tel : 01 4734 2525
> Fax : 01 4734 2535
> 23 rue des volontaires
> 75015 PARIS
>
> Pensez aux services :
> Assistance tИlИphonique
> Assistance sur site
> Maintenance informatique
> Ticket de service
> Pack service Internet
>
>
>
> -----Message d'origine-----
> De : Zoran Knezevic [mailto:zoka@hotbox.ru]
> EnvoyИ : vendredi 14 novembre 2003 10:47
> ю : smarty-general@lists.php.net
> Objet : [SMARTY] How to use Smarty to make mail templates and send > them
>
> Hi,
>
> I would like to make mail template using smarty and
> send it. I guess it is something like the "capture"
> function and then send variable as usual from php...
>
> Is there any example arround?
>
> Thank you in advance.
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>