Skip to content

Commit 13262a4

Browse files
committed
Mailer implemented
1 parent d6af2b2 commit 13262a4

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

berry/email.php

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

berry/utils.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
require_once(__DIR__ . "/utils/CrawlerDetector.php");
44
require_once(__DIR__ . "/utils/HTMLHelper.php");
5+
require_once(__DIR__ . "/utils/Mailer.php");
56
?>

berry/utils/Mailer.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
class Mailer
4+
{
5+
6+
public function __construct()
7+
{
8+
9+
}
10+
11+
/**
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+
*/
20+
public function SendEmail(string $htmlContent, string $subject, string $fromEmail, string $fromTitle, string $toEmail): bool
21+
{
22+
$fromTitle = strip_tags($fromTitle);
23+
$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);
27+
}
28+
29+
}
30+
31+
?>

debug.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
<?php
2-
require_once(__DIR__ . "/berry/encryption.php"); // Include berry encryption package
2+
require_once(__DIR__ . "/berry/utils.php"); // Include berry utils package
33

4-
$encryptionKey = "%2IR5wdW%Q7bLE*v+v4WpNfM*pkeM4sz"; // 32characters encryption key
5-
$stringToEncrypt = "This is a simple text we need to encrypt";
4+
// Initialize a new Mailer
5+
$mailer = new Mailer();
66

7-
print "Original String: " . $stringToEncrypt."<br>";
7+
$htmlContent = '<h1>Email Title</h1>';
8+
$htmlContent .= '<div>Dear customer, this is Elon Musk...</div>';
89

9-
$encryptedString = AES256Encryption::encrypt($encryptionKey,$stringToEncrypt);
10-
print "Encrypted String: " . $encryptedString."<br>";
10+
$subject = "Email subject...";
11+
$fromEmail = "elonmusk@email.com";
12+
$fromTitle = "Elon Musk";
13+
$toEmail = "customer@customer.com";
1114

12-
$descryptedString = AES256Encryption::decrypt($encryptionKey, $encryptedString);
13-
print "Decrypted String: " . $descryptedString."<br>";
15+
if (!$mailer->SendEmail($htmlContent, $subject, $fromEmail, $fromTitle, $toEmail))
16+
{
17+
print "Unable to send the email!";
18+
}
1419
?>

0 commit comments

Comments
 (0)