@@ -175,12 +175,12 @@ class Mail
175175
176176 private readonly Configuration $ configuration ;
177177
178- /*
178+ /**
179179 * Default constructor.
180180 * Note: any email will be sent from the PMF administrator, use unsetFrom
181181 * before using setFrom.
182182 *
183- * @param Configuration $config
183+ * @param Configuration $configuration
184184 */
185185 public function __construct (Configuration $ configuration )
186186 {
@@ -204,7 +204,7 @@ public function __construct(Configuration $configuration)
204204 try {
205205 $ this ->setFrom ($ this ->configuration ->getAdminEmail (), $ this ->configuration ->getTitle ());
206206 } catch (Exception ) {
207- // @todo handle exception
207+ // Silently ignore when admin email is not configured
208208 }
209209 }
210210
@@ -228,7 +228,8 @@ public static function createBoundary(): string
228228 public static function getServerName (): string
229229 {
230230 $ request = Request::createFromGlobals ();
231- return $ request ->getHost () ?: 'localhost.localdomain ' ;
231+ $ host = $ request ->getHost ();
232+ return $ host !== '' && $ host !== null ? $ host : 'localhost.localdomain ' ;
232233 }
233234
234235 /**
@@ -259,13 +260,11 @@ private function setEmailTo(array &$target, string $targetAlias, string $address
259260 // Check for the permitted number of items into the $target array
260261 if (count ($ target ) > 2 ) {
261262 $ keys = array_keys ($ target );
262- throw new Exception (
263- sprintf ('Too many e-mail addresses, %s, ' , $ keys [0 ])
264- . sprintf (
265- format: "have been already added as '%s'! " ,
266- values: $ targetAlias ,
267- ),
268- );
263+ throw new Exception (sprintf (
264+ "Too many e-mail addresses, %s, have been already added as '%s'! " ,
265+ $ keys [0 ],
266+ $ targetAlias ,
267+ ));
269268 }
270269
271270 return $ this ->addEmailTo ($ target , $ targetAlias , $ address , $ name );
@@ -409,7 +408,7 @@ public function send(): int
409408 }
410409
411410 // Has any attachment been provided?
412- if (! empty ($ this ->attachments )) {
411+ if (count ($ this ->attachments ) > 0 ) {
413412 $ this ->contentType = 'multipart/mixed ' ;
414413 }
415414
@@ -431,7 +430,7 @@ public function send(): int
431430 // Prepare the recipients
432431 $ to = [];
433432 foreach ($ this ->to as $ address => $ name ) {
434- $ to [] = (empty ( $ name) ? '' : $ name . ' ' ) . '< ' . $ address . '> ' ;
433+ $ to [] = ($ name !== null && $ name !== '' ? $ name . ' ' : ' ' ) . '< ' . $ address . '> ' ;
435434 }
436435
437436 $ recipients = implode (
@@ -495,7 +494,7 @@ private function createHeaders(): void
495494 // Disposition-Notification-To, RFC 3798
496495 $ notifyTos = [];
497496 foreach ($ this ->notifyTo as $ address => $ name ) {
498- $ notifyTos [] = (empty ( $ name) ? '' : $ name . ' ' ) . '< ' . $ address . '> ' ;
497+ $ notifyTos [] = ($ name !== null && $ name !== '' ? $ name . ' ' : ' ' ) . '< ' . $ address . '> ' ;
499498 }
500499
501500 $ notifyTo = implode (
@@ -508,17 +507,17 @@ private function createHeaders(): void
508507
509508 // From
510509 foreach ($ this ->from as $ address => $ name ) {
511- $ this ->headers ['From ' ] = (empty ( $ name) ? '' : $ name . ' ' ) . '< ' . $ address . '> ' ;
510+ $ this ->headers ['From ' ] = ($ name !== null && $ name !== '' ? $ name . ' ' : ' ' ) . '< ' . $ address . '> ' ;
512511 }
513512
514513 // CC
515514 foreach ($ this ->cc as $ address => $ name ) {
516- $ this ->headers ['CC ' ] = (empty ( $ name) ? '' : $ name . ' ' ) . '< ' . $ address . '> ' ;
515+ $ this ->headers ['CC ' ] = ($ name !== null && $ name !== '' ? $ name . ' ' : ' ' ) . '< ' . $ address . '> ' ;
517516 }
518517
519518 // BCC
520519 foreach ($ this ->bcc as $ address => $ name ) {
521- $ this ->headers ['BCC ' ] = (empty ( $ name) ? '' : $ name . ' ' ) . '< ' . $ address . '> ' ;
520+ $ this ->headers ['BCC ' ] = ($ name !== null && $ name !== '' ? $ name . ' ' : ' ' ) . '< ' . $ address . '> ' ;
522521 }
523522
524523 // Message-Id
@@ -530,7 +529,7 @@ private function createHeaders(): void
530529 // Reply-To
531530 $ this ->headers ['Reply-To ' ] = $ this ->headers ['From ' ];
532531 foreach ($ this ->replyTo as $ address => $ name ) {
533- $ this ->headers ['Reply-To ' ] = (empty ( $ name) ? '' : $ name . ' ' ) . '< ' . $ address . '> ' ;
532+ $ this ->headers ['Reply-To ' ] = ($ name !== null && $ name !== '' ? $ name . ' ' : ' ' ) . '< ' . $ address . '> ' ;
534533 }
535534
536535 // Return-Path
@@ -545,7 +544,7 @@ private function createHeaders(): void
545544 // Sender
546545 $ this ->headers ['Sender ' ] = $ this ->headers ['From ' ];
547546 foreach ($ this ->sender as $ address => $ name ) {
548- $ this ->headers ['Sender ' ] = (empty ( $ name) ? '' : $ name . ' ' ) . '< ' . $ address . '> ' ;
547+ $ this ->headers ['Sender ' ] = ($ name !== null && $ name !== '' ? $ name . ' ' : ' ' ) . '< ' . $ address . '> ' ;
549548 }
550549
551550 // Subject. Note: it must be RFC 2047 compliant
0 commit comments