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