clsEmail.inc.php
3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* @author Prefeitura Municipal de Itajaí *
* @updated 29/03/2007 *
* Pacote: i-PLB Software Público Livre e Brasileiro *
* *
* Copyright (C) 2006 PMI - Prefeitura Municipal de Itajaí *
* ctima@itajai.sc.gov.br *
* *
* Este programa é software livre, você pode redistribuí-lo e/ou *
* modificá-lo sob os termos da Licença Pública Geral GNU, conforme *
* publicada pela Free Software Foundation, tanto a versão 2 da *
* Licença como (a seu critério) qualquer versão mais nova. *
* *
* Este programa é distribuído na expectativa de ser útil, mas SEM *
* QUALQUER GARANTIA. Sem mesmo a garantia implícita de COMERCIALI- *
* ZAÇÃO ou de ADEQUAÇÃO A QUALQUER PROPÓSITO EM PARTICULAR. Con- *
* sulte a Licença Pública Geral GNU para obter mais detalhes. *
* *
* Você deve ter recebido uma cópia da Licença Pública Geral GNU *
* junto com este programa. Se não, escreva para a Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA *
* 02111-1307, USA. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
class clsEmail
{
var $remetente;
var $remetenteNome;
var $replyto;
var $destinatarios;
var $assunto;
var $conteudo;
var $template;
var $footer;
var $tipo;
var $compilado;
var $conteudoCompilado;
var $charset = "iso-8859-1";
function clsEmail( $destinatarios, $assunto, $conteudo, $template=false, $remetente=false, $remetenteNome=false, $replyto=false, $tipo="html", $strFooter=false )
{
$this->compilado = false;
$this->destinatarios = $destinatarios;
$this->assunto = $assunto;
$this->conteudo = $conteudo;
$this->footer = $strFooter;
$this->template = ( $template )? $template : "email_padrao";
$this->remetente = ( $remetente )? $remetente: "sistema@itajai.sc.gov.br";
$this->remetenteNome = ( $remetenteNome ) ? $remetenteNome: "Sistema - Itajai.sc.gov.br";
$this->replyto = ( $replyto )? $replyto: $remetente;
$this->tipo = ( $tipo == "html" )? "text/html": "text/plain";
}
function compilar()
{
if( $this->tipo != "text/html" )
{
$this->conteudoCompilado = $this->conteudo;
}
else
{
$arquivo = "templates/{$this->template}.tpl";
$ptrTpl = fopen( $arquivo, "r");
$strArquivo = fread($ptrTpl, filesize($arquivo));
fclose ($ptrTpl);
$strArquivo = str_replace( "<!-- #&CONTEUDO&# -->", $this->conteudo, $strArquivo );
$strArquivo = str_replace( "<!-- #&ASSUNTO&# -->", $this->assunto, $strArquivo );
if( $this->footer )
{
$strArquivo = str_replace( "<!-- #&FOOTER&# -->", $this->footer, $strArquivo );
}
$this->conteudoCompilado = $strArquivo;
}
$this->compilado = true;
}
function envia()
{
if( ! $this->compilado ) $this->compilar();
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: {$this->tipo}; charset={$this->charset}\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
$headers .= "X-Mailer: php/" . phpversion() . "\n";
$headers .= "From: \"{$this->remetenteNome}\" <{$this->remetente}>\n";
$headers .= "Reply-To: {$this->replyto}\n";
if( is_array( $this->destinatarios ) )
{
$this->destinatarios = implode( ",", $this->destinatarios );
}
$this->destinatarios = str_replace( " ", ",", $this->destinatarios );
$ok = mail( $this->destinatarios, $this->assunto, $this->conteudoCompilado, $headers );
return $ok;
}
function addDestinatario( $email )
{
if( is_array( $this->destinatarios ) )
{
$this->destinatarios[] = $email;
}
else
{
if( $this->destinatarios != "" )
{
$this->destinatarios .= ",{$email}";
}
else
{
$this->destinatarios = $email;
}
}
}
}
?>