-
Notifications
You must be signed in to change notification settings - Fork 0
/
Email.php
129 lines (122 loc) · 2.66 KB
/
Email.php
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
120
121
122
123
124
125
126
127
128
129
<?php
namespace BlueSeed;
/**
*
* The controller to support interpretation of requests
* @author ivonascimento <[email protected]>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
*
*/
use BlueSeed\Communication\Mailable;
class Email {
/**
*
* the Mailable InstanceMailable
* @var Mailable
*/
private $mailmethod;
/**
*
* the Message Body
* @var string
*/
private $body;
/**
*
* Mail Subject
* @var string
*/
private $subject;
/**
*
* the e-mail of sender
* @var string
*/
private $from;
/**
*
* the e-mail to (can by maore then one)
* @var string
*/
private $to;
/**
*
* Constructor where the Mail Pear are Instanciate
* @param Maileble $mailObject
* @return void
*/
public function __construct(Mailable $mailObject){
$this->mailmethod = $mailObject;
}
/**
*
* setter to Body
* @param string
* @return void
*/
public function setBody($str){
$this->body = $str;
return $this;
}
/**Mailable
*
* setter to Subject
* @param string $str
* @return void
*/
public function setSubject($str){
$this->subject = $str;
return $this;
}
/**
*
* setter to From
* @param string $mailfrom
* @return void
*/
public function setFrom($mailfrom){
$this->from = $mailfrom;
return $this;
}
/**
*
* setter to TO
* @param string $mailto
* @return void
*/
public function setTo($mailto){
$this->to = $mailto;
return $this;
}
/**
*
* Send the email
* @param boolean $asHTML
* @return void
*/
public function send($asHTML = true){
if ( !($this->body && $this->from && $this->subject && $this->to) )
throw New \Exception ("Falha ao enviar e-mail. Os dados não foram informados.");
$headers = array("From"=>$this->from, "Subject"=>$this->subject );
if ($asHTML){
$headers['Content-type'] = 'text/html; charset=iso-UTF-8';
}
try{
$return = $this->mailmethod->send( $this->to, $headers, $this->body);
}catch ( \Exception $E){
throw New \Exception("Falha ao enviar e-mail usando Pear/Mail");
}
}
/**
*
* reset the data to prepare a New Mail if all data is newer
* @return void
*/
public function clearData(){
$this->body = "";
$this->subject = "";
$this->from = "";
$this->to = "";
}
}
?>