|
3 | 3 | class Mailer
|
4 | 4 | {
|
5 | 5 |
|
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") |
7 | 14 | {
|
8 |
| - |
| 15 | + $this->fCharset = $charset; |
9 | 16 | }
|
10 | 17 |
|
11 | 18 | /**
|
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 |
19 | 26 | */
|
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 |
21 | 28 | {
|
22 |
| - $fromTitle = strip_tags($fromTitle); |
| 29 | + $senderName = strip_tags($senderName); |
23 | 30 | $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); |
27 | 35 | }
|
28 | 36 |
|
29 | 37 | }
|
|
0 commit comments