11
11
*
12
12
* @property string $sender
13
13
* @property string $subject
14
- * @property string $encoding
15
14
* @property array $headers
16
15
* @property array $body
17
16
* @property array $attachments
@@ -58,22 +57,29 @@ class Mailer {
58
57
protected $ attachments ;
59
58
60
59
/**
61
- * Encoding of message .
60
+ * Mailer constructor .
62
61
*
63
- * @var string
62
+ * @param string $sender
64
63
*/
65
- protected $ encoding = 'utf8 ' ;
64
+ public function __construct ($ sender ='admin@localhost ' )
65
+ {
66
+ $ this ->sender = (string )$ sender ;
67
+ $ this ->reset ();
68
+ }
66
69
67
70
/**
68
- * Mailer constructor .
71
+ * Set sender .
69
72
*
70
- * @param string $sender
71
- * @param string $encoding
73
+ * @param string $senderEmail
74
+ * @param string $senderName
72
75
*/
73
- public function __construct ( $ sender = ' admin@localhost ' , $ encoding = ' utf8 ' )
76
+ public function sender ( $ senderEmail , $ senderName = ' ' )
74
77
{
75
- $ this ->sender = (string )$ sender ;
76
- $ this ->encoding = preg_replace ('/[^a-z0-9]/ui ' ,'' ,mb_strtolower ((string )$ encoding ));
78
+ $ this ->sender = (string )$ senderEmail ;
79
+ $ senderName = (string )$ senderName ;
80
+ if ($ senderName ) {
81
+ $ this ->sender .= '< ' .$ senderName .'> ' ;
82
+ }
77
83
$ this ->reset ();
78
84
}
79
85
@@ -98,7 +104,7 @@ public function body($text)
98
104
{
99
105
$ this ->body = [
100
106
'headers ' => [
101
- 'Content-Type ' => 'text/html; charset= ' . $ this -> encoding ,
107
+ 'Content-Type ' => 'text/html; charset=utf8 ' ,
102
108
],
103
109
'content ' => (string )$ text ,
104
110
];
@@ -227,7 +233,7 @@ protected function getBodySimpleText()
227
233
$ this ->setHeader ($ header , $ value , true );
228
234
}
229
235
}
230
- $ this ->setHeader ('Content-type ' ,'text/html; charset= ' . $ this -> encoding , true );
236
+ $ this ->setHeader ('Content-type ' ,'text/html; charset=utf8 ' , true );
231
237
return isset ($ this ->body ['content ' ])?(string )$ this ->body ['content ' ]:'' ;
232
238
}
233
239
@@ -243,15 +249,9 @@ protected function getBodyMultipart()
243
249
$ this ->setHeader ('Content-Type ' , 'multipart/mixed; boundary=" ' .$ separator .'" ' , true );
244
250
$ this ->setHeader ('Content-Transfer-Encoding ' , '7bit ' , true );
245
251
$ body [] = null ;
246
- $ b = $ eol .'Content-type: text/html; charset= ' .$ this ->encoding .$ eol ;
247
- $ bits = '7bit ' ;
248
- switch ($ this ->encoding ) {
249
- case 'utf8 ' :
250
- $ bits ='8bit ' ;
251
- break ;
252
- }
252
+ $ b = $ eol .'Content-type: text/html; charset=utf8 ' .$ eol ;
253
253
$ message = isset ($ this ->body ['content ' ])?$ this ->body ['content ' ]:null ;
254
- $ b .= 'Content-Transfer-Encoding: ' . $ bits .$ eol ;
254
+ $ b .= 'Content-Transfer-Encoding: 8bit ' .$ eol ;
255
255
$ b .= $ eol .$ message .$ eol ;
256
256
$ body [] = $ b ;
257
257
foreach ($ this ->attachments as $ attachment =>$ data ) {
0 commit comments