4
4
5
5
namespace Codefy \Framework \Helpers ;
6
6
7
+ use Codefy \Framework \Application ;
7
8
use Codefy \Framework \Codefy ;
8
9
use Codefy \Framework \Factory \FileLoggerFactory ;
9
10
use Codefy \Framework \Support \CodefyMailer ;
@@ -148,25 +149,10 @@ function mail(string|array $to, string $subject, string $message, array $headers
148
149
$ instance = $ instance ->withTo (address: $ to );
149
150
150
151
// Set from name and from email from environment variables.
151
- __observer ()->filter ->addFilter ('mail.from.name ' , fn () => env (key: 'MAILER_FROM_NAME ' ));
152
- __observer ()->filter ->addFilter ('mail.from.email ' , fn () => env (key: 'MAILER_FROM_EMAIL ' ));
152
+ $ fromName = __observer ()->filter ->applyFilter ('mail.from.name ' , env (key: 'MAILER_FROM_NAME ' ));
153
+ $ fromEmail = __observer ()->filter ->applyFilter ('mail.from.email ' , env (key: 'MAILER_FROM_EMAIL ' ));
153
154
// Set charset
154
- __observer ()->filter ->addFilter ('mail.charset ' , fn () => 'utf-8 ' );
155
-
156
- // Loop through the filters.
157
- foreach (__observer ()->filter ->getHooks () as $ hook ) {
158
- if ($ hook ['hook ' ] === 'mail.from.name ' ) {
159
- $ fromName = $ hook ['callback ' ]();
160
- }
161
-
162
- if ($ hook ['hook ' ] === 'mail.from.email ' ) {
163
- $ fromEmail = $ hook ['callback ' ]();
164
- }
165
-
166
- if ($ hook ['hook ' ] === 'mail.charset ' ) {
167
- $ charset = $ hook ['callback ' ]();
168
- }
169
- }
155
+ $ charset = __observer ()->filter ->applyFilter ('mail.charset ' , fn () => 'utf-8 ' );
170
156
171
157
// Set email subject and body.
172
158
$ instance = $ instance ->withSubject (subject: $ subject )->withBody (data: $ message );
@@ -196,7 +182,7 @@ function mail(string|array $to, string $subject, string $message, array $headers
196
182
$ instance = $ instance ->withXMailer (xmailer: 'CodefyPHP Framework ' . Application::APP_VERSION );
197
183
198
184
// Set email charset
199
- $ instance = $ instance ->withCharset (charset: $ charset ?? 'utf-8 ' );
185
+ $ instance = $ instance ->withCharset (charset: $ charset ?: 'utf-8 ' );
200
186
201
187
// Check if there are attachments and loop through them.
202
188
if (!empty ($ attachments )) {
@@ -207,7 +193,7 @@ function mail(string|array $to, string $subject, string $message, array $headers
207
193
}
208
194
209
195
// Set sender.
210
- $ instance = $ instance ->withFrom (address: $ fromEmail ?? '' , name: $ fromName ?? '' );
196
+ $ instance = $ instance ->withFrom (address: $ fromEmail , name: $ fromName ?: '' );
211
197
212
198
try {
213
199
return $ instance ->send ();
0 commit comments