1+ <?php
2+
3+ class EMail
4+ {
5+
6+ private string $ fCharset ;
7+ private string $ fSenderEmailAddress ;
8+ private string $ fSenderName = "" ;
9+ private string $ fRecipientEmailAddress ;
10+ private string $ fSubject = "" ;
11+ private string $ fHTMLContent = "" ;
12+
13+ /**
14+ * Initialize a new email object
15+ * @param string $charset is the default charset to use for this email.
16+ * Leave empty for UTF-8
17+ */
18+ public function __construct (string $ charset = "UTF-8 " )
19+ {
20+ $ this ->fCharset = $ charset ;
21+ }
22+
23+ /**
24+ * Returns the charset of this email
25+ * @return string the charset of this email
26+ */
27+ public function getCharset (): string
28+ {
29+ return $ this ->fCharset ;
30+ }
31+
32+ /**
33+ * Sets the sender's email address
34+ * @param string $senderEmail the email address of the sender
35+ */
36+ public function setSenderAddress (string $ senderEmail ): void
37+ {
38+ $ this ->fSenderEmailAddress = $ senderEmail ;
39+ }
40+
41+ /**
42+ * Return's the sender's email address
43+ * @return string the sender's email address
44+ */
45+ public function getSenderAddress (): string
46+ {
47+ return $ this ->fSenderEmailAddress ;
48+ }
49+
50+ /**
51+ * Sets the sender's name
52+ * @param string the email address of the sender
53+ */
54+ public function setSenderName (string $ senderName ): void
55+ {
56+ $ this ->fSenderName = strip_tags ($ senderName );
57+ }
58+
59+ /**
60+ * Return's the sender's name
61+ * @return string the name of the sender
62+ */
63+ public function getSenderName (): string
64+ {
65+ return $ this ->fSenderName ;
66+ }
67+
68+ /**
69+ * Sets the recipient's email address
70+ * @param string the email address of the recipient
71+ */
72+ public function setRecipientAddress (string $ recipientAddress ): void
73+ {
74+ $ this ->fRecipientEmailAddress = $ recipientAddress ;
75+ }
76+
77+ /**
78+ * Return's the recipient's email address
79+ * @return string the recipient's email address
80+ */
81+ public function getRecipientEmailAddress (): string
82+ {
83+ return $ this ->fRecipientEmailAddress ;
84+ }
85+
86+ /**
87+ * Sets the subject of this email
88+ * @param string $subject
89+ * @return void
90+ */
91+ public function setSubject (string $ subject ): void
92+ {
93+ $ this ->fSubject = strip_tags ($ subject );
94+ }
95+
96+ /**
97+ * Return's the subject of this email
98+ * @return string the subject of this email
99+ */
100+ public function getSubject (): string
101+ {
102+ return $ this ->fSubject ;
103+ }
104+
105+ /**
106+ * Sets the HTML content of this email
107+ * @param string $htmlContent the content of this email
108+ * @return void
109+ */
110+ public function setHTMLContent (string $ htmlContent ): void
111+ {
112+ $ this ->fHTMLContent = $ htmlContent ;
113+ }
114+
115+ /**
116+ * Return's the content of this email
117+ * @return string the html content of this email
118+ */
119+ public function getHTMLContent (): string
120+ {
121+ return $ this ->fHTMLContent ;
122+ }
123+
124+ /**
125+ * Tries to send this email.
126+ * @return bool true if email sent, otherwise false
127+ */
128+ public function Send (): bool
129+ {
130+ $ header = "From: " . $ this ->fSenderName . " < " . $ this ->fSenderEmailAddress . "> \r\n" ;
131+ $ header .= "Content-type: text/html;charset= " . $ this ->fCharset . "\r\n" ;
132+ return mail ($ this ->fRecipientEmailAddress , '=?UTF-8?B? ' . base64_encode ($ this ->fSubject ) . '?= ' , $ this ->fHTMLContent , $ header );
133+ }
134+
135+ }
136+
137+ ?>
0 commit comments