1*ee5c0205SAndreas Gohr<?php 2*ee5c0205SAndreas Gohr/***************************************************\ 3*ee5c0205SAndreas Gohr * 4*ee5c0205SAndreas Gohr * Mailer (https://github.com/txthinking/Mailer) 5*ee5c0205SAndreas Gohr * 6*ee5c0205SAndreas Gohr * A lightweight PHP SMTP mail sender. 7*ee5c0205SAndreas Gohr * Implement RFC0821, RFC0822, RFC1869, RFC2045, RFC2821 8*ee5c0205SAndreas Gohr * 9*ee5c0205SAndreas Gohr * Support html body, don't worry that the receiver's 10*ee5c0205SAndreas Gohr * mail client can't support html, because Mailer will 11*ee5c0205SAndreas Gohr * send both text/plain and text/html body, so if the 12*ee5c0205SAndreas Gohr * mail client can't support html, it will display the 13*ee5c0205SAndreas Gohr * text/plain body. 14*ee5c0205SAndreas Gohr * 15*ee5c0205SAndreas Gohr * Create Date 2012-07-25. 16*ee5c0205SAndreas Gohr * Under the MIT license. 17*ee5c0205SAndreas Gohr * 18*ee5c0205SAndreas Gohr \***************************************************/ 19*ee5c0205SAndreas Gohrnamespace Tx\Mailer; 20*ee5c0205SAndreas Gohr 21*ee5c0205SAndreas Gohrclass Message 22*ee5c0205SAndreas Gohr{ 23*ee5c0205SAndreas Gohr /** 24*ee5c0205SAndreas Gohr * from name 25*ee5c0205SAndreas Gohr */ 26*ee5c0205SAndreas Gohr protected $fromName; 27*ee5c0205SAndreas Gohr 28*ee5c0205SAndreas Gohr /** 29*ee5c0205SAndreas Gohr * from email 30*ee5c0205SAndreas Gohr */ 31*ee5c0205SAndreas Gohr protected $fromEmail; 32*ee5c0205SAndreas Gohr 33*ee5c0205SAndreas Gohr /** 34*ee5c0205SAndreas Gohr * fake from name 35*ee5c0205SAndreas Gohr */ 36*ee5c0205SAndreas Gohr protected $fakeFromName; 37*ee5c0205SAndreas Gohr 38*ee5c0205SAndreas Gohr /** 39*ee5c0205SAndreas Gohr * fake from email 40*ee5c0205SAndreas Gohr */ 41*ee5c0205SAndreas Gohr protected $fakeFromEmail; 42*ee5c0205SAndreas Gohr 43*ee5c0205SAndreas Gohr /** 44*ee5c0205SAndreas Gohr * to email 45*ee5c0205SAndreas Gohr */ 46*ee5c0205SAndreas Gohr protected $to = array(); 47*ee5c0205SAndreas Gohr 48*ee5c0205SAndreas Gohr /** 49*ee5c0205SAndreas Gohr * cc email 50*ee5c0205SAndreas Gohr */ 51*ee5c0205SAndreas Gohr protected $cc = array(); 52*ee5c0205SAndreas Gohr 53*ee5c0205SAndreas Gohr /** 54*ee5c0205SAndreas Gohr * bcc email 55*ee5c0205SAndreas Gohr */ 56*ee5c0205SAndreas Gohr protected $bcc = array(); 57*ee5c0205SAndreas Gohr 58*ee5c0205SAndreas Gohr /** 59*ee5c0205SAndreas Gohr * mail subject 60*ee5c0205SAndreas Gohr */ 61*ee5c0205SAndreas Gohr protected $subject; 62*ee5c0205SAndreas Gohr 63*ee5c0205SAndreas Gohr /** 64*ee5c0205SAndreas Gohr * mail body 65*ee5c0205SAndreas Gohr */ 66*ee5c0205SAndreas Gohr protected $body; 67*ee5c0205SAndreas Gohr 68*ee5c0205SAndreas Gohr /** 69*ee5c0205SAndreas Gohr *mail attachment 70*ee5c0205SAndreas Gohr */ 71*ee5c0205SAndreas Gohr protected $attachment = array(); 72*ee5c0205SAndreas Gohr 73*ee5c0205SAndreas Gohr /** 74*ee5c0205SAndreas Gohr * message header 75*ee5c0205SAndreas Gohr */ 76*ee5c0205SAndreas Gohr protected $header = array(); 77*ee5c0205SAndreas Gohr 78*ee5c0205SAndreas Gohr /** 79*ee5c0205SAndreas Gohr * charset 80*ee5c0205SAndreas Gohr */ 81*ee5c0205SAndreas Gohr protected $charset = "UTF-8"; 82*ee5c0205SAndreas Gohr 83*ee5c0205SAndreas Gohr /** 84*ee5c0205SAndreas Gohr * header multipart boundaryMixed 85*ee5c0205SAndreas Gohr */ 86*ee5c0205SAndreas Gohr protected $boundaryMixed; 87*ee5c0205SAndreas Gohr 88*ee5c0205SAndreas Gohr /** 89*ee5c0205SAndreas Gohr * header multipart alternative 90*ee5c0205SAndreas Gohr */ 91*ee5c0205SAndreas Gohr protected $boundaryAlternative; 92*ee5c0205SAndreas Gohr 93*ee5c0205SAndreas Gohr /** 94*ee5c0205SAndreas Gohr * $this->CRLF 95*ee5c0205SAndreas Gohr * @var string 96*ee5c0205SAndreas Gohr */ 97*ee5c0205SAndreas Gohr protected $CRLF = "\r\n"; 98*ee5c0205SAndreas Gohr 99*ee5c0205SAndreas Gohr 100*ee5c0205SAndreas Gohr /** 101*ee5c0205SAndreas Gohr * Address for the reply-to header 102*ee5c0205SAndreas Gohr * @var string 103*ee5c0205SAndreas Gohr */ 104*ee5c0205SAndreas Gohr protected $replyToName; 105*ee5c0205SAndreas Gohr 106*ee5c0205SAndreas Gohr /** 107*ee5c0205SAndreas Gohr * Address for the reply-to header 108*ee5c0205SAndreas Gohr * @var string 109*ee5c0205SAndreas Gohr */ 110*ee5c0205SAndreas Gohr protected $replyToEmail; 111*ee5c0205SAndreas Gohr 112*ee5c0205SAndreas Gohr 113*ee5c0205SAndreas Gohr public function setReplyTo($name, $email) 114*ee5c0205SAndreas Gohr { 115*ee5c0205SAndreas Gohr $this->replyToName = $name; 116*ee5c0205SAndreas Gohr $this->replyToEmail = $email; 117*ee5c0205SAndreas Gohr return $this; 118*ee5c0205SAndreas Gohr } 119*ee5c0205SAndreas Gohr 120*ee5c0205SAndreas Gohr 121*ee5c0205SAndreas Gohr /** 122*ee5c0205SAndreas Gohr * set mail from 123*ee5c0205SAndreas Gohr * @param string $name 124*ee5c0205SAndreas Gohr * @param string $email 125*ee5c0205SAndreas Gohr * @return $this 126*ee5c0205SAndreas Gohr */ 127*ee5c0205SAndreas Gohr public function setFrom($name, $email) 128*ee5c0205SAndreas Gohr { 129*ee5c0205SAndreas Gohr $this->fromName = $name; 130*ee5c0205SAndreas Gohr $this->fromEmail = $email; 131*ee5c0205SAndreas Gohr return $this; 132*ee5c0205SAndreas Gohr } 133*ee5c0205SAndreas Gohr 134*ee5c0205SAndreas Gohr 135*ee5c0205SAndreas Gohr /** 136*ee5c0205SAndreas Gohr * set mail fake from 137*ee5c0205SAndreas Gohr * @param string $name 138*ee5c0205SAndreas Gohr * @param string $email 139*ee5c0205SAndreas Gohr * @return $this 140*ee5c0205SAndreas Gohr */ 141*ee5c0205SAndreas Gohr public function setFakeFrom($name, $email) 142*ee5c0205SAndreas Gohr { 143*ee5c0205SAndreas Gohr $this->fakeFromName = $name; 144*ee5c0205SAndreas Gohr $this->fakeFromEmail = $email; 145*ee5c0205SAndreas Gohr return $this; 146*ee5c0205SAndreas Gohr } 147*ee5c0205SAndreas Gohr 148*ee5c0205SAndreas Gohr /** 149*ee5c0205SAndreas Gohr * add mail receiver 150*ee5c0205SAndreas Gohr * @param string $name 151*ee5c0205SAndreas Gohr * @param string $email 152*ee5c0205SAndreas Gohr * @return $this 153*ee5c0205SAndreas Gohr */ 154*ee5c0205SAndreas Gohr public function addTo($name, $email) 155*ee5c0205SAndreas Gohr { 156*ee5c0205SAndreas Gohr $this->to[$email] = $name; 157*ee5c0205SAndreas Gohr return $this; 158*ee5c0205SAndreas Gohr } 159*ee5c0205SAndreas Gohr 160*ee5c0205SAndreas Gohr /** 161*ee5c0205SAndreas Gohr * add cc mail receiver 162*ee5c0205SAndreas Gohr * @param string $name 163*ee5c0205SAndreas Gohr * @param string $email 164*ee5c0205SAndreas Gohr * @return $this 165*ee5c0205SAndreas Gohr */ 166*ee5c0205SAndreas Gohr public function addCc($name, $email) 167*ee5c0205SAndreas Gohr { 168*ee5c0205SAndreas Gohr $this->cc[$email] = $name; 169*ee5c0205SAndreas Gohr return $this; 170*ee5c0205SAndreas Gohr } 171*ee5c0205SAndreas Gohr 172*ee5c0205SAndreas Gohr /** 173*ee5c0205SAndreas Gohr * add bcc mail receiver 174*ee5c0205SAndreas Gohr * @param string $name 175*ee5c0205SAndreas Gohr * @param string $email 176*ee5c0205SAndreas Gohr * @return $this 177*ee5c0205SAndreas Gohr */ 178*ee5c0205SAndreas Gohr public function addBcc($name, $email) 179*ee5c0205SAndreas Gohr { 180*ee5c0205SAndreas Gohr $this->bcc[$email] = $name; 181*ee5c0205SAndreas Gohr return $this; 182*ee5c0205SAndreas Gohr } 183*ee5c0205SAndreas Gohr 184*ee5c0205SAndreas Gohr /** 185*ee5c0205SAndreas Gohr * set mail subject 186*ee5c0205SAndreas Gohr * @param string $subject 187*ee5c0205SAndreas Gohr * @return $this 188*ee5c0205SAndreas Gohr */ 189*ee5c0205SAndreas Gohr public function setSubject($subject) 190*ee5c0205SAndreas Gohr { 191*ee5c0205SAndreas Gohr $this->subject = $subject; 192*ee5c0205SAndreas Gohr return $this; 193*ee5c0205SAndreas Gohr } 194*ee5c0205SAndreas Gohr 195*ee5c0205SAndreas Gohr /** 196*ee5c0205SAndreas Gohr * set mail body 197*ee5c0205SAndreas Gohr * @param string $body 198*ee5c0205SAndreas Gohr * @return $this 199*ee5c0205SAndreas Gohr */ 200*ee5c0205SAndreas Gohr public function setBody($body) 201*ee5c0205SAndreas Gohr { 202*ee5c0205SAndreas Gohr $this->body = $body; 203*ee5c0205SAndreas Gohr return $this; 204*ee5c0205SAndreas Gohr } 205*ee5c0205SAndreas Gohr 206*ee5c0205SAndreas Gohr /** 207*ee5c0205SAndreas Gohr * add mail attachment 208*ee5c0205SAndreas Gohr * @param $name 209*ee5c0205SAndreas Gohr * @param $path 210*ee5c0205SAndreas Gohr * @return $this 211*ee5c0205SAndreas Gohr */ 212*ee5c0205SAndreas Gohr public function addAttachment($name, $path) 213*ee5c0205SAndreas Gohr { 214*ee5c0205SAndreas Gohr $this->attachment[$name] = $path; 215*ee5c0205SAndreas Gohr return $this; 216*ee5c0205SAndreas Gohr } 217*ee5c0205SAndreas Gohr 218*ee5c0205SAndreas Gohr /** 219*ee5c0205SAndreas Gohr * @return string 220*ee5c0205SAndreas Gohr */ 221*ee5c0205SAndreas Gohr public function getFromName() 222*ee5c0205SAndreas Gohr { 223*ee5c0205SAndreas Gohr return $this->fromName; 224*ee5c0205SAndreas Gohr } 225*ee5c0205SAndreas Gohr 226*ee5c0205SAndreas Gohr /** 227*ee5c0205SAndreas Gohr * @return string 228*ee5c0205SAndreas Gohr */ 229*ee5c0205SAndreas Gohr public function getFromEmail() 230*ee5c0205SAndreas Gohr { 231*ee5c0205SAndreas Gohr return $this->fromEmail; 232*ee5c0205SAndreas Gohr } 233*ee5c0205SAndreas Gohr 234*ee5c0205SAndreas Gohr 235*ee5c0205SAndreas Gohr /** 236*ee5c0205SAndreas Gohr * @return string 237*ee5c0205SAndreas Gohr */ 238*ee5c0205SAndreas Gohr public function getFakeFromName() 239*ee5c0205SAndreas Gohr { 240*ee5c0205SAndreas Gohr return $this->fakeFromName; 241*ee5c0205SAndreas Gohr } 242*ee5c0205SAndreas Gohr 243*ee5c0205SAndreas Gohr /** 244*ee5c0205SAndreas Gohr * @return string 245*ee5c0205SAndreas Gohr */ 246*ee5c0205SAndreas Gohr public function getFakeFromEmail() 247*ee5c0205SAndreas Gohr { 248*ee5c0205SAndreas Gohr return $this->fakeFromEmail; 249*ee5c0205SAndreas Gohr } 250*ee5c0205SAndreas Gohr 251*ee5c0205SAndreas Gohr /** 252*ee5c0205SAndreas Gohr * @return mixed 253*ee5c0205SAndreas Gohr */ 254*ee5c0205SAndreas Gohr public function getTo() 255*ee5c0205SAndreas Gohr { 256*ee5c0205SAndreas Gohr return $this->to; 257*ee5c0205SAndreas Gohr } 258*ee5c0205SAndreas Gohr 259*ee5c0205SAndreas Gohr /** 260*ee5c0205SAndreas Gohr * @return mixed 261*ee5c0205SAndreas Gohr */ 262*ee5c0205SAndreas Gohr public function getCc() 263*ee5c0205SAndreas Gohr { 264*ee5c0205SAndreas Gohr return $this->cc; 265*ee5c0205SAndreas Gohr } 266*ee5c0205SAndreas Gohr 267*ee5c0205SAndreas Gohr /** 268*ee5c0205SAndreas Gohr * @return mixed 269*ee5c0205SAndreas Gohr */ 270*ee5c0205SAndreas Gohr public function getBcc() 271*ee5c0205SAndreas Gohr { 272*ee5c0205SAndreas Gohr return $this->bcc; 273*ee5c0205SAndreas Gohr } 274*ee5c0205SAndreas Gohr 275*ee5c0205SAndreas Gohr /** 276*ee5c0205SAndreas Gohr * @return mixed 277*ee5c0205SAndreas Gohr */ 278*ee5c0205SAndreas Gohr public function getSubject() 279*ee5c0205SAndreas Gohr { 280*ee5c0205SAndreas Gohr return $this->subject; 281*ee5c0205SAndreas Gohr } 282*ee5c0205SAndreas Gohr 283*ee5c0205SAndreas Gohr /** 284*ee5c0205SAndreas Gohr * @return mixed 285*ee5c0205SAndreas Gohr */ 286*ee5c0205SAndreas Gohr public function getBody() 287*ee5c0205SAndreas Gohr { 288*ee5c0205SAndreas Gohr return $this->body; 289*ee5c0205SAndreas Gohr } 290*ee5c0205SAndreas Gohr 291*ee5c0205SAndreas Gohr /** 292*ee5c0205SAndreas Gohr * @return array 293*ee5c0205SAndreas Gohr */ 294*ee5c0205SAndreas Gohr public function getAttachment() 295*ee5c0205SAndreas Gohr { 296*ee5c0205SAndreas Gohr return $this->attachment; 297*ee5c0205SAndreas Gohr } 298*ee5c0205SAndreas Gohr 299*ee5c0205SAndreas Gohr /** 300*ee5c0205SAndreas Gohr * Create mail header 301*ee5c0205SAndreas Gohr * @return $this 302*ee5c0205SAndreas Gohr */ 303*ee5c0205SAndreas Gohr protected function createHeader() 304*ee5c0205SAndreas Gohr { 305*ee5c0205SAndreas Gohr $this->header['Date'] = date('r'); 306*ee5c0205SAndreas Gohr 307*ee5c0205SAndreas Gohr $fromName = ""; 308*ee5c0205SAndreas Gohr $fromEmail = $this->fromEmail; 309*ee5c0205SAndreas Gohr if(!empty($this->fromName)){ 310*ee5c0205SAndreas Gohr $fromName = sprintf("=?utf-8?B?%s?= ", base64_encode($this->fromName)); 311*ee5c0205SAndreas Gohr } 312*ee5c0205SAndreas Gohr if(!empty($this->fakeFromEmail)){ 313*ee5c0205SAndreas Gohr if(!empty($this->fakeFromName)){ 314*ee5c0205SAndreas Gohr $fromName = sprintf("=?utf-8?B?%s?= ", base64_encode($this->fakeFromName)); 315*ee5c0205SAndreas Gohr } 316*ee5c0205SAndreas Gohr $fromEmail = $this->fakeFromEmail; 317*ee5c0205SAndreas Gohr } 318*ee5c0205SAndreas Gohr $this->header['Return-Path'] = $fromEmail; 319*ee5c0205SAndreas Gohr $this->header['From'] = $fromName . "<" . $fromEmail .">"; 320*ee5c0205SAndreas Gohr 321*ee5c0205SAndreas Gohr $this->header['To'] = ''; 322*ee5c0205SAndreas Gohr foreach ($this->to as $toEmail => $toName) { 323*ee5c0205SAndreas Gohr if(!empty($toName)){ 324*ee5c0205SAndreas Gohr $toName = sprintf("=?utf-8?B?%s?= ", base64_encode($toName)); 325*ee5c0205SAndreas Gohr } 326*ee5c0205SAndreas Gohr $this->header['To'] .= $toName . "<" . $toEmail . ">, "; 327*ee5c0205SAndreas Gohr } 328*ee5c0205SAndreas Gohr $this->header['To'] = substr($this->header['To'], 0, -2); 329*ee5c0205SAndreas Gohr $this->header['Cc'] = ''; 330*ee5c0205SAndreas Gohr foreach ($this->cc as $toEmail => $toName) { 331*ee5c0205SAndreas Gohr if(!empty($toName)){ 332*ee5c0205SAndreas Gohr $toName = sprintf("=?utf-8?B?%s?= ", base64_encode($toName)); 333*ee5c0205SAndreas Gohr } 334*ee5c0205SAndreas Gohr $this->header['Cc'] .= $toName . "<" . $toEmail . ">, "; 335*ee5c0205SAndreas Gohr } 336*ee5c0205SAndreas Gohr $this->header['Cc'] = substr($this->header['Cc'], 0, -2); 337*ee5c0205SAndreas Gohr $this->header['Bcc'] = ''; 338*ee5c0205SAndreas Gohr foreach ($this->bcc as $toEmail => $toName) { 339*ee5c0205SAndreas Gohr if(!empty($toName)){ 340*ee5c0205SAndreas Gohr $toName = sprintf("=?utf-8?B?%s?= ", base64_encode($toName)); 341*ee5c0205SAndreas Gohr } 342*ee5c0205SAndreas Gohr $this->header['Bcc'] .= $toName . "<" . $toEmail . ">, "; 343*ee5c0205SAndreas Gohr } 344*ee5c0205SAndreas Gohr $this->header['Bcc'] = substr($this->header['Bcc'], 0, -2); 345*ee5c0205SAndreas Gohr 346*ee5c0205SAndreas Gohr $replyToName = ""; 347*ee5c0205SAndreas Gohr if(!empty($this->replyToName)){ 348*ee5c0205SAndreas Gohr $replyToName = sprintf("=?utf-8?B?%s?= ", base64_encode($this->replyToName)); 349*ee5c0205SAndreas Gohr } 350*ee5c0205SAndreas Gohr $this->header['Reply-To'] = $replyToName . "<" . $this->replyToEmail . ">"; 351*ee5c0205SAndreas Gohr 352*ee5c0205SAndreas Gohr if(empty($this->subject)){ 353*ee5c0205SAndreas Gohr $subject = ''; 354*ee5c0205SAndreas Gohr }else{ 355*ee5c0205SAndreas Gohr $subject = sprintf("=?utf-8?B?%s?= ", base64_encode($this->subject)); 356*ee5c0205SAndreas Gohr } 357*ee5c0205SAndreas Gohr $this->header['Subject'] = $subject; 358*ee5c0205SAndreas Gohr 359*ee5c0205SAndreas Gohr $this->header['Message-ID'] = '<' . md5(uniqid()) . '@' . $this->fromEmail . '>'; 360*ee5c0205SAndreas Gohr $this->header['X-Priority'] = '3'; 361*ee5c0205SAndreas Gohr $this->header['X-Mailer'] = 'Mailer (https://github.com/txthinking/Mailer)'; 362*ee5c0205SAndreas Gohr $this->header['MIME-Version'] = '1.0'; 363*ee5c0205SAndreas Gohr if (!empty($this->attachment)){ 364*ee5c0205SAndreas Gohr $this->boundaryMixed = md5(md5(time().'TxMailer').uniqid()); 365*ee5c0205SAndreas Gohr $this->header['Content-Type'] = "multipart/mixed; \r\n\tboundary=\"" . $this->boundaryMixed . "\""; 366*ee5c0205SAndreas Gohr } 367*ee5c0205SAndreas Gohr $this->boundaryAlternative = md5(md5(time().'TXMailer').uniqid()); 368*ee5c0205SAndreas Gohr return $this; 369*ee5c0205SAndreas Gohr } 370*ee5c0205SAndreas Gohr 371*ee5c0205SAndreas Gohr /** 372*ee5c0205SAndreas Gohr * @brief createBody create body 373*ee5c0205SAndreas Gohr * 374*ee5c0205SAndreas Gohr * @return string 375*ee5c0205SAndreas Gohr */ 376*ee5c0205SAndreas Gohr protected function createBody() 377*ee5c0205SAndreas Gohr { 378*ee5c0205SAndreas Gohr $in = ""; 379*ee5c0205SAndreas Gohr $in .= "Content-Type: multipart/alternative; boundary=\"$this->boundaryAlternative\"" . $this->CRLF; 380*ee5c0205SAndreas Gohr $in .= $this->CRLF; 381*ee5c0205SAndreas Gohr $in .= "--" . $this->boundaryAlternative . $this->CRLF; 382*ee5c0205SAndreas Gohr $in .= "Content-Type: text/plain; charset=\"" . $this->charset . "\"" . $this->CRLF; 383*ee5c0205SAndreas Gohr $in .= "Content-Transfer-Encoding: base64" . $this->CRLF; 384*ee5c0205SAndreas Gohr $in .= $this->CRLF; 385*ee5c0205SAndreas Gohr $in .= chunk_split(base64_encode($this->body)) . $this->CRLF; 386*ee5c0205SAndreas Gohr $in .= $this->CRLF; 387*ee5c0205SAndreas Gohr $in .= "--" . $this->boundaryAlternative . $this->CRLF; 388*ee5c0205SAndreas Gohr $in .= "Content-Type: text/html; charset=\"" . $this->charset ."\"" . $this->CRLF; 389*ee5c0205SAndreas Gohr $in .= "Content-Transfer-Encoding: base64" . $this->CRLF; 390*ee5c0205SAndreas Gohr $in .= $this->CRLF; 391*ee5c0205SAndreas Gohr $in .= chunk_split(base64_encode($this->body)) . $this->CRLF; 392*ee5c0205SAndreas Gohr $in .= $this->CRLF; 393*ee5c0205SAndreas Gohr $in .= "--" . $this->boundaryAlternative . "--" . $this->CRLF; 394*ee5c0205SAndreas Gohr return $in; 395*ee5c0205SAndreas Gohr } 396*ee5c0205SAndreas Gohr 397*ee5c0205SAndreas Gohr /** 398*ee5c0205SAndreas Gohr * @brief createBodyWithAttachment create body with attachment 399*ee5c0205SAndreas Gohr * 400*ee5c0205SAndreas Gohr * @return string 401*ee5c0205SAndreas Gohr */ 402*ee5c0205SAndreas Gohr protected function createBodyWithAttachment() 403*ee5c0205SAndreas Gohr { 404*ee5c0205SAndreas Gohr $in = ""; 405*ee5c0205SAndreas Gohr $in .= $this->CRLF; 406*ee5c0205SAndreas Gohr $in .= $this->CRLF; 407*ee5c0205SAndreas Gohr $in .= '--' . $this->boundaryMixed . $this->CRLF; 408*ee5c0205SAndreas Gohr $in .= "Content-Type: multipart/alternative; boundary=\"$this->boundaryAlternative\"" . $this->CRLF; 409*ee5c0205SAndreas Gohr $in .= $this->CRLF; 410*ee5c0205SAndreas Gohr $in .= "--" . $this->boundaryAlternative . $this->CRLF; 411*ee5c0205SAndreas Gohr $in .= "Content-Type: text/plain; charset=\"" . $this->charset . "\"" . $this->CRLF; 412*ee5c0205SAndreas Gohr $in .= "Content-Transfer-Encoding: base64" . $this->CRLF; 413*ee5c0205SAndreas Gohr $in .= $this->CRLF; 414*ee5c0205SAndreas Gohr $in .= chunk_split(base64_encode($this->body)) . $this->CRLF; 415*ee5c0205SAndreas Gohr $in .= $this->CRLF; 416*ee5c0205SAndreas Gohr $in .= "--" . $this->boundaryAlternative . $this->CRLF; 417*ee5c0205SAndreas Gohr $in .= "Content-Type: text/html; charset=\"" . $this->charset ."\"" . $this->CRLF; 418*ee5c0205SAndreas Gohr $in .= "Content-Transfer-Encoding: base64" . $this->CRLF; 419*ee5c0205SAndreas Gohr $in .= $this->CRLF; 420*ee5c0205SAndreas Gohr $in .= chunk_split(base64_encode($this->body)) . $this->CRLF; 421*ee5c0205SAndreas Gohr $in .= $this->CRLF; 422*ee5c0205SAndreas Gohr $in .= "--" . $this->boundaryAlternative . "--" . $this->CRLF; 423*ee5c0205SAndreas Gohr foreach ($this->attachment as $name => $path){ 424*ee5c0205SAndreas Gohr $in .= $this->CRLF; 425*ee5c0205SAndreas Gohr $in .= '--' . $this->boundaryMixed . $this->CRLF; 426*ee5c0205SAndreas Gohr $in .= "Content-Type: application/octet-stream; name=\"". $name ."\"" . $this->CRLF; 427*ee5c0205SAndreas Gohr $in .= "Content-Transfer-Encoding: base64" . $this->CRLF; 428*ee5c0205SAndreas Gohr $in .= "Content-Disposition: attachment; filename=\"" . $name . "\"" . $this->CRLF; 429*ee5c0205SAndreas Gohr $in .= $this->CRLF; 430*ee5c0205SAndreas Gohr $in .= chunk_split(base64_encode(file_get_contents($path))) . $this->CRLF; 431*ee5c0205SAndreas Gohr } 432*ee5c0205SAndreas Gohr $in .= $this->CRLF; 433*ee5c0205SAndreas Gohr $in .= $this->CRLF; 434*ee5c0205SAndreas Gohr $in .= '--' . $this->boundaryMixed . '--' . $this->CRLF; 435*ee5c0205SAndreas Gohr return $in; 436*ee5c0205SAndreas Gohr } 437*ee5c0205SAndreas Gohr 438*ee5c0205SAndreas Gohr public function toString() 439*ee5c0205SAndreas Gohr { 440*ee5c0205SAndreas Gohr $in = ''; 441*ee5c0205SAndreas Gohr $this->createHeader(); 442*ee5c0205SAndreas Gohr foreach ($this->header as $key => $value) { 443*ee5c0205SAndreas Gohr $in .= $key . ': ' . $value . $this->CRLF; 444*ee5c0205SAndreas Gohr } 445*ee5c0205SAndreas Gohr if (empty($this->attachment)) { 446*ee5c0205SAndreas Gohr $in .= $this->createBody(); 447*ee5c0205SAndreas Gohr } else { 448*ee5c0205SAndreas Gohr $in .= $this->createBodyWithAttachment(); 449*ee5c0205SAndreas Gohr } 450*ee5c0205SAndreas Gohr $in .= $this->CRLF . $this->CRLF . "." . $this->CRLF; 451*ee5c0205SAndreas Gohr return $in; 452*ee5c0205SAndreas Gohr } 453*ee5c0205SAndreas Gohr 454*ee5c0205SAndreas Gohr} 455