create-prisma-php-app 1.16.4 → 1.16.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/composer.json +2 -1
- package/dist/src/Lib/PHPMailer/Mailer.php +15 -4
- package/dist/src/Lib/Validator.php +16 -0
- package/package.json +1 -1
package/composer.json
CHANGED
|
@@ -45,20 +45,20 @@ class Mailer
|
|
|
45
45
|
{
|
|
46
46
|
try {
|
|
47
47
|
// Validate and sanitize inputs
|
|
48
|
-
|
|
48
|
+
$to = Validator::email($to);
|
|
49
|
+
if (!$to) {
|
|
49
50
|
throw new \Exception('Invalid email address for the main recipient');
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
$subject = Validator::string($subject);
|
|
53
|
-
$body = Validator::
|
|
54
|
+
$body = Validator::html($body);
|
|
55
|
+
$altBody = $this->convertToPlainText($body);
|
|
54
56
|
|
|
55
57
|
$name = $options['name'] ?? '';
|
|
56
|
-
$altBody = $options['altBody'] ?? '';
|
|
57
58
|
$addCC = $options['addCC'] ?? [];
|
|
58
59
|
$addBCC = $options['addBCC'] ?? [];
|
|
59
60
|
|
|
60
61
|
$name = Validator::string($name);
|
|
61
|
-
$altBody = Validator::string($altBody);
|
|
62
62
|
|
|
63
63
|
// Handle CC recipients
|
|
64
64
|
$this->handleRecipients($addCC, 'CC');
|
|
@@ -111,4 +111,15 @@ class Mailer
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Convert HTML content to plain text.
|
|
117
|
+
*
|
|
118
|
+
* @param string $html The HTML content to convert.
|
|
119
|
+
* @return string The plain text content.
|
|
120
|
+
*/
|
|
121
|
+
private function convertToPlainText(string $html): string
|
|
122
|
+
{
|
|
123
|
+
return strip_tags(str_replace(['<br>', '<br/>', '<br />', '</p>'], "\n", $html));
|
|
124
|
+
}
|
|
114
125
|
}
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
namespace Lib;
|
|
4
4
|
|
|
5
|
+
use HTMLPurifier;
|
|
6
|
+
use HTMLPurifier_Config;
|
|
7
|
+
|
|
5
8
|
class Validator
|
|
6
9
|
{
|
|
7
10
|
// String Validation
|
|
@@ -194,4 +197,17 @@ class Validator
|
|
|
194
197
|
{
|
|
195
198
|
return in_array($value, $allowedValues, true);
|
|
196
199
|
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Purify and sanitize HTML content.
|
|
203
|
+
*
|
|
204
|
+
* @param string $html The HTML content to purify.
|
|
205
|
+
* @return string The purified HTML content.
|
|
206
|
+
*/
|
|
207
|
+
public static function html(string $html): string
|
|
208
|
+
{
|
|
209
|
+
$config = HTMLPurifier_Config::createDefault();
|
|
210
|
+
$purifier = new HTMLPurifier($config);
|
|
211
|
+
return $purifier->purify($html);
|
|
212
|
+
}
|
|
197
213
|
}
|