1111 *
1212 * @property string $sender
1313 * @property string $subject
14- * @property string $encoding
1514 * @property array $headers
1615 * @property array $body
1716 * @property array $attachments
@@ -58,22 +57,29 @@ class Mailer {
5857 protected $ attachments ;
5958
6059 /**
61- * Encoding of message .
60+ * Mailer constructor .
6261 *
63- * @var string
62+ * @param string $sender
6463 */
65- protected $ encoding = 'utf8 ' ;
64+ public function __construct ($ sender ='admin@localhost ' )
65+ {
66+ $ this ->sender = (string )$ sender ;
67+ $ this ->reset ();
68+ }
6669
6770 /**
68- * Mailer constructor .
71+ * Set sender .
6972 *
70- * @param string $sender
71- * @param string $encoding
73+ * @param string $senderEmail
74+ * @param string $senderName
7275 */
73- public function __construct ( $ sender = ' admin@localhost ' , $ encoding = ' utf8 ' )
76+ public function sender ( $ senderEmail , $ senderName = ' ' )
7477 {
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+ }
7783 $ this ->reset ();
7884 }
7985
@@ -98,7 +104,7 @@ public function body($text)
98104 {
99105 $ this ->body = [
100106 'headers ' => [
101- 'Content-Type ' => 'text/html; charset= ' . $ this -> encoding ,
107+ 'Content-Type ' => 'text/html; charset=utf8 ' ,
102108 ],
103109 'content ' => (string )$ text ,
104110 ];
@@ -227,7 +233,7 @@ protected function getBodySimpleText()
227233 $ this ->setHeader ($ header , $ value , true );
228234 }
229235 }
230- $ this ->setHeader ('Content-type ' ,'text/html; charset= ' . $ this -> encoding , true );
236+ $ this ->setHeader ('Content-type ' ,'text/html; charset=utf8 ' , true );
231237 return isset ($ this ->body ['content ' ])?(string )$ this ->body ['content ' ]:'' ;
232238 }
233239
@@ -243,15 +249,9 @@ protected function getBodyMultipart()
243249 $ this ->setHeader ('Content-Type ' , 'multipart/mixed; boundary=" ' .$ separator .'" ' , true );
244250 $ this ->setHeader ('Content-Transfer-Encoding ' , '7bit ' , true );
245251 $ 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 ;
253253 $ message = isset ($ this ->body ['content ' ])?$ this ->body ['content ' ]:null ;
254- $ b .= 'Content-Transfer-Encoding: ' . $ bits .$ eol ;
254+ $ b .= 'Content-Transfer-Encoding: 8bit ' .$ eol ;
255255 $ b .= $ eol .$ message .$ eol ;
256256 $ body [] = $ b ;
257257 foreach ($ this ->attachments as $ attachment =>$ data ) {
0 commit comments