Skip to content

Commit d0ab131

Browse files
committed
implementing email object
1 parent d67a255 commit d0ab131

File tree

4 files changed

+147
-8
lines changed

4 files changed

+147
-8
lines changed

berry/email.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
<?php
22

3+
require_once(__DIR__ . "/email/EMail.php");
4+
5+
?>

berry/email/EMail.php

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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+
?>

berry/utils/Mailer.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,18 @@ public function __construct(string $charset = "UTF-8")
1616
}
1717

1818
/**
19-
* Sends an HTML content email.
20-
* @param string $htmlContent is the content of the email to send.
21-
* @param string $subject is the subject of the email to send.
22-
* @param string $senderAddress is the sender's email address.
23-
* @param string $senderName is the sender's name.
19+
* Sends an HTML content email
20+
* @param string $htmlContent is the content of the email to send
21+
* @param string $subject is the subject of the email to send
22+
* @param string $senderAddress is the sender's email address
23+
* @param string $senderName is the sender's name
2424
* @param string $recepientEmail is the recipient's email address
2525
* @return bool true if email sent, otherwise false
2626
*/
2727
public function SendEmail(string $htmlContent, string $subject, string $senderAddress, string $senderName, string $recepientEmail): bool
2828
{
2929
$senderName = strip_tags($senderName);
3030
$subject = strip_tags($subject);
31-
3231
$header = "From: " . $senderName . " <" . $senderAddress . ">\r\n";
3332
$header .= "Content-type: text/html;charset=" . $this->fCharset . "\r\n";
3433
return mail($recepientEmail, '=?UTF-8?B?' . base64_encode($subject) . '?=', $htmlContent, $header);

nbproject/private/private.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
44
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
55
<group>
6-
<file>file:/C:/Development/php-berry/berry/encryption/AES256Encryption.php</file>
7-
<file>file:/C:/Development/php-berry/debug.php</file>
6+
<file>file:/C:/Development/php-berry/berry/email/EMail.php</file>
7+
<file>file:/C:/Development/php-berry/berry/utils/Mailer.php</file>
88
</group>
99
</open-files>
1010
</project-private>

0 commit comments

Comments
 (0)