Skip to content

Commit d67a255

Browse files
committed
Mailer implemented
1 parent 13262a4 commit d67a255

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

berry/utils/Mailer.php

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,35 @@
33
class Mailer
44
{
55

6-
public function __construct()
6+
private string $fCharset = "UTF-8";
7+
8+
/**
9+
* Initialize a new Mailer object
10+
* @param string $charset is the default charset to use for this Mailer.
11+
* Leave empty for UTF-8
12+
*/
13+
public function __construct(string $charset = "UTF-8")
714
{
8-
15+
$this->fCharset = $charset;
916
}
1017

1118
/**
12-
*
13-
* @param string $htmlContent
14-
* @param string $subject
15-
* @param string $fromEmail
16-
* @param string $fromTitle
17-
* @param string $toEmail
18-
* @return bool
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.
24+
* @param string $recepientEmail is the recipient's email address
25+
* @return bool true if email sent, otherwise false
1926
*/
20-
public function SendEmail(string $htmlContent, string $subject, string $fromEmail, string $fromTitle, string $toEmail): bool
27+
public function SendEmail(string $htmlContent, string $subject, string $senderAddress, string $senderName, string $recepientEmail): bool
2128
{
22-
$fromTitle = strip_tags($fromTitle);
29+
$senderName = strip_tags($senderName);
2330
$subject = strip_tags($subject);
24-
$header = "From: " . $fromTitle . " <" . $fromEmail . ">\r\n";
25-
$header .= "Content-type: text/html;charset=UTF-8\r\n";
26-
return mail($toEmail, '=?UTF-8?B?' . base64_encode($subject) . '?=', $htmlContent, $header);
31+
32+
$header = "From: " . $senderName . " <" . $senderAddress . ">\r\n";
33+
$header .= "Content-type: text/html;charset=" . $this->fCharset . "\r\n";
34+
return mail($recepientEmail, '=?UTF-8?B?' . base64_encode($subject) . '?=', $htmlContent, $header);
2735
}
2836

2937
}

debug.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
$subject = "Email subject...";
1111
$fromEmail = "elonmusk@email.com";
1212
$fromTitle = "Elon Musk";
13-
$toEmail = "customer@customer.com";
13+
$toEmail = "customer@customerdomain.com";
1414

1515
if (!$mailer->SendEmail($htmlContent, $subject, $fromEmail, $fromTitle, $toEmail))
1616
{

0 commit comments

Comments
 (0)