@@ -97,7 +97,9 @@ public function addTo($email, $name = "")
97
97
98
98
public function removeTo ($ email )
99
99
{
100
- if (array_key_exists ($ email , $ this ->to )) unset($ this ->to [$ email ]);
100
+ if (array_key_exists ($ email , $ this ->to )) {
101
+ unset($ this ->to [$ email ]);
102
+ }
101
103
$ this ->replaceHeaderTo ();
102
104
return $ this ;
103
105
}
@@ -116,7 +118,9 @@ public function addCc($email, $name = "")
116
118
117
119
public function removeCc ($ email )
118
120
{
119
- if (array_key_exists ($ email , $ this ->cc )) unset($ this ->cc [$ email ]);
121
+ if (array_key_exists ($ email , $ this ->cc )) {
122
+ unset($ this ->cc [$ email ]);
123
+ }
120
124
$ this ->replaceHeaderCc ();
121
125
return $ this ;
122
126
}
@@ -135,7 +139,9 @@ public function addBcc($email, $name = "")
135
139
136
140
public function removeBcc ($ email )
137
141
{
138
- if (array_key_exists ($ email , $ this ->bcc )) unset($ this ->bcc [$ email ]);
142
+ if (array_key_exists ($ email , $ this ->bcc )) {
143
+ unset($ this ->bcc [$ email ]);
144
+ }
139
145
$ this ->replaceHeaderBcc ();
140
146
return $ this ;
141
147
}
@@ -148,8 +154,12 @@ public function getBcc()
148
154
public function setFrom ($ email , $ name = "" )
149
155
{
150
156
$ email = (string )$ email ;
151
- if (!$ email ) return $ this ;
152
- if (!$ this ->checkEmail ($ email )) return $ this ;
157
+ if (!$ email ) {
158
+ return $ this ;
159
+ }
160
+ if (!$ this ->checkEmail ($ email )) {
161
+ return $ this ;
162
+ }
153
163
$ contact = $ this ->getContact ($ email , $ name );
154
164
$ this ->setHeaderRaw ("From " , $ contact );
155
165
return $ this ;
@@ -269,7 +279,7 @@ private function createBodyMessagePlainPart($content)
269
279
{
270
280
$ text = "\r\nContent-type: text/plain; charset=UTF-8 \r\n" ;
271
281
$ text .= "Content-Transfer-Encoding: base64 \r\n\r\n" ;
272
- $ text .= chunk_split ($ content ). "\r\n" ;
282
+ $ text .= chunk_split ($ content ) . "\r\n" ;
273
283
return $ text ;
274
284
}
275
285
@@ -282,7 +292,7 @@ private function createBodyMessageHtmlPart($content)
282
292
283
293
$ part = "\r\nContent-type: text/html; charset=UTF-8 \r\n" ;
284
294
$ part .= "Content-Transfer-Encoding: base64 \r\n\r\n" ;
285
- $ part .= chunk_split ($ content ). "\r\n" ;
295
+ $ part .= chunk_split ($ content ) . "\r\n" ;
286
296
$ parts [] = $ part ;
287
297
$ parts [] = "-- " ;
288
298
$ text .= implode ("-- $ boundary " , $ parts );
@@ -299,7 +309,7 @@ public function getBody()
299
309
$ part = "\r\nContent-type: {$ attachment ["mime " ]}; name= $ name \r\n" ;
300
310
$ part .= "Content-Transfer-Encoding: base64 \r\n" ;
301
311
$ part .= "Content-Disposition: attachment \r\n\r\n" ;
302
- $ part .= chunk_split ($ attachment ["content " ]). "\r\n" ;
312
+ $ part .= chunk_split ($ attachment ["content " ]) . "\r\n" ;
303
313
$ parts [] = $ part ;
304
314
}
305
315
$ parts [] = "-- " ;
@@ -317,7 +327,7 @@ public function getPersonalMessages()
317
327
{
318
328
$ result = array ();
319
329
$ recipients = array_replace ($ this ->to , $ this ->cc , $ this ->bcc );
320
- foreach ($ recipients as $ email=> $ recipient ) {
330
+ foreach ($ recipients as $ email => $ recipient ) {
321
331
$ clone = clone $ this ;
322
332
$ clone ->to = array (
323
333
$ email => $ recipient ,
@@ -362,13 +372,23 @@ private function checkEmail($email)
362
372
private function addAddress ($ type , $ email , $ name )
363
373
{
364
374
$ email = (string )$ email ;
365
- if (!$ email ) return false ;
366
- if (!$ this ->checkEmail ($ email )) return false ;
375
+ if (!$ email ) {
376
+ return false ;
377
+ }
378
+ if (!$ this ->checkEmail ($ email )) {
379
+ return false ;
380
+ }
367
381
$ contact = $ this ->getContact ($ email , $ name );
368
382
switch ($ type ) {
369
- case "to " : $ this ->to [$ email ] = $ contact ; break ;
370
- case "cc " : $ this ->cc [$ email ] = $ contact ; break ;
371
- case "bcc " : $ this ->bcc [$ email ] = $ contact ; break ;
383
+ case "to " :
384
+ $ this ->to [$ email ] = $ contact ;
385
+ break ;
386
+ case "cc " :
387
+ $ this ->cc [$ email ] = $ contact ;
388
+ break ;
389
+ case "bcc " :
390
+ $ this ->bcc [$ email ] = $ contact ;
391
+ break ;
372
392
}
373
393
return true ;
374
394
}
@@ -391,10 +411,14 @@ private function replaceHeaderBcc()
391
411
private function getContact ($ email , $ name = "" )
392
412
{
393
413
$ email = (string )$ email ;
394
- $ name = preg_replace ("/[^\pL\s\,\ .\d]/ui " , "" , (string )$ name );
414
+ $ name = preg_replace ("/[^\pL\s, .\d]/ui " , "" , (string )$ name );
395
415
$ name = trim ($ name );
396
- if (preg_match ("/[^a-z0-9\s]+/ui " , $ name )) $ name = $ this ->headerEncode ($ name );
397
- if ($ name ) $ name = "$ name " ;
416
+ if (preg_match ("/[^a-z0-9\s]+/ui " , $ name )) {
417
+ $ name = $ this ->headerEncode ($ name );
418
+ }
419
+ if ($ name ) {
420
+ $ name = "$ name " ;
421
+ }
398
422
return "$ name< $ email> " ;
399
423
}
400
424
@@ -426,7 +450,7 @@ public function unserialize($serialized)
426
450
"bcc " => array (),
427
451
"boundary " => md5 (time ()),
428
452
);
429
- foreach ($ keys as $ key=> $ default ) {
453
+ foreach ($ keys as $ key => $ default ) {
430
454
$ this ->$ key = array_key_exists ($ key , $ raw ) ? $ raw [$ key ] : $ default ;
431
455
}
432
456
}
@@ -436,4 +460,4 @@ private function headerEncode($value)
436
460
$ value = mb_encode_mimeheader ($ value , "UTF-8 " , "B " , "\r\n" , 0 );
437
461
return $ value ;
438
462
}
439
- }
463
+ }
0 commit comments