PHP Classes

PHP HTML Formatted Mail : Send HTML email messages composed using templates

Recommend this page to a friend!
  Info   Example   Screenshots   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 565 All time: 5,414 This week: 78Up
Version License PHP version Categories
send-formatted-mail 1.0.0GNU General Publi...4HTML, Email, Templates
Description 

Author

This class can send HTML email messages composed using templates.

It can compose message bodies from templates that are processed with PHPlib template processor.

The compose HTML messages can be sent by the MIME mail message. Messages may include embedded images.

Picture of José Filipe Lopes Santos
  Performance   Level  
Innovation award
Innovation award
Nominee: 1x

 

Recommendations

Send emails fast
I need to send many emails

Example

<?php

/* form with
 * name
 * email
 * subject
 * message
 *
 * send to mail ....
 */


/**
 * Send ticket by email.
 *
 * @author José Filipe Lopes Santos <jfilipe@med.up.pt>
 * @since 09-05-2012
 * @version 1.0 - data da últ. actualização: 10-05-2012
 */

require_once 'conf/core.inc';
require_once
'lib/sendmail.inc';

/* ---------------------------------- oOo --------------------------------
                             Inicialização de variáveis
   ---------------------------------- oOo -------------------------------- */

if (empty($name)) $name = "";
if (empty(
$email)) $email = "";
if (empty(
$subject)) $subject = "";
if (empty(
$message)) $message = "";
if (empty(
$note_empty)) $note_empty = false; // booleano que indica se existem campos obrigatórios por preencher
if (empty($error_msg)) $error_msg = ""; // mensagem de erro
if (empty($sended)) $sended = "no"; // indica se já foi enviado ou não o ticket por email
if (empty($title)) $title = "Send a ticket";


/* ---------------------------------- oOo --------------------------------
             Verificar se existem campos obrigatórios por preencher
   ---------------------------------- oOo -------------------------------- */

if (!empty($submit) && ($name == "" || $email == ""))
   
$note_empty = true;
else
   
$note_empty = false;


/* ---------------------------------- oOo --------------------------------
                                  Enviar mails
   ---------------------------------- oOo -------------------------------- */

if (!empty($submit) && !$note_empty && $error_msg == ""){

   
// remetente / de e destinatário / para
   
$from = "Trouble Tickets (tts) <tts@med.up.pt>";
       
$to = "jfilipe@med.up.pt";

   
// criar uma nova instânca da classe para enviar mails
   
$sm = new sendmail(CRLF);

   
// adicionar template
   
$sm->addTemplate("page","mail_page.html");
       
$sm->addTemplate("info","info_ticket.html");
   
   
// mensagem de erro
   
if ($sm->error_msg != "") die("erro: ".$sm->error_msg."\n");

       
// adicionar imagem
       
$sm->addImage("images/cabecalho.gif","image/gif","cabecalho.gif");
               
   
// determinar os cabeçalhos
   
$subject_mail = "Ticket: ".$subject;
   
$headers = array("From" => $from, "Subject" => $subject_mail);

       
// Information to formatted message
        // can be get from database record
       
$info = array("name" => $name, "email" => $email, "subject" => $subject, "message" => $message);
               
   
// obter a mensagem formatada
       
$message = $sm->genFormattedMailMessage("ticket",$info,TEMPLATES_PATH,$subject_mail);

   
// mensagem de erro
   
if ($sm->error_msg != "") die("erro: ".$sm->error_msg."\n");

   
// enviar a mensagem
   
$sm->Send($message,$to,$headers);
   
   
// mensagem de erro
   
if ($sm->error_msg != "") die("erro: ".$sm->error_msg."\n");
       
       
$sended = "yes";
}

/* ---------------------------------- oOo --------------------------------
                     Output
   ---------------------------------- oOo -------------------------------- */


$t = new Template_PHPLIB(TEMPLATES_PATH);
             
$t->setFile(array("page" => "page.html",
                 
"form" => "form_ticket.html",
                 
"note" => "note_without_table.html",
         
"note2" => "note_without_table.html"));


//*********** Página (início) *************
$t->setVar(array("rooturl" => ROOT_URL, "titulo" => $title));


if (
ereg("yes",$sended)){ // enviado

    //*********** mensagem de sucesso *******
   
$t->setVar("msg","Ticket sended with sucess");
   
$t->parse("block_body","note",true);
   
} else {

   
//////// destacar os campos por preencher ///////////
   
if (!empty($submit) && $name == "") $t->setVar("symbol_name",SYMBOL_EMPTY);
    else
$t->setVar("symbol_name",SYMBOL_NORMAL);
    if (!empty(
$submit) && $email == "") $t->setVar("symbol_email",SYMBOL_EMPTY);
    else
$t->setVar("symbol_email",SYMBOL_NORMAL);

   
/////// setar variáveis //////
   
$t->setVar(array("name_value" => $name,
                    
"email_value" => $email,
                    
"subject_value" => $subject,
                    
"message_value" => $message));


   
//************* mensagem de erro ***********
   
if ($error_msg == "" && $note_empty) $error_msg = MSG_EMPTY;
    if (
$error_msg != ""){
           
$t->setVar(array("colspan_note" => 2, "msg" => $error_msg));
           
$t->parse("block_note","note2",true);
    }

   
//********** formulário (fim) **********
   
$t->parse("block_body","form",true);

}

//*********** Página (fim) *************
$t->pparse("output","page");

?>


Screenshots (2)  
  • form
  • mail
  Files folder image Files (22)  
File Role Description
Files folder imageSendFormattedMail (1 file, 6 directories)

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:565
This week:0
All time:5,414
This week:78Up