| 96 | | /** |
|---|
| 97 | | * Sets the text-only body of the message. This automatically sets the |
|---|
| 98 | | * email to multipart/alternative. This body can be read by mail |
|---|
| 99 | | * clients that do not have HTML email capability such as mutt. Clients |
|---|
| 100 | | * that can read HTML will view the normal Body. |
|---|
| 101 | | * @var string |
|---|
| 102 | | */ |
|---|
| 103 | | public $AltBody = ""; |
|---|
| 104 | | |
|---|
| 105 | | /** |
|---|
| 106 | | * Sets word wrapping on the body of the message to a given number of |
|---|
| 107 | | * characters. |
|---|
| 108 | | * @var int |
|---|
| 109 | | */ |
|---|
| 110 | | public $WordWrap = 0; |
|---|
| 111 | | |
|---|
| 112 | | /** |
|---|
| 113 | | * Method to send mail: ("mail", "sendmail", or "smtp"). |
|---|
| 114 | | * @var string |
|---|
| 115 | | */ |
|---|
| 116 | | public $Mailer = "mail"; |
|---|
| 117 | | |
|---|
| 118 | | /** |
|---|
| 119 | | * Sets the path of the sendmail program. |
|---|
| 120 | | * @var string |
|---|
| 121 | | */ |
|---|
| 122 | | public $Sendmail = "/usr/sbin/sendmail"; |
|---|
| 123 | | |
|---|
| 124 | | /** |
|---|
| 125 | | * Holds PHPMailer version. |
|---|
| 126 | | * @var string |
|---|
| 127 | | */ |
|---|
| 128 | | public $Version = "1.73"; |
|---|
| 129 | | |
|---|
| 130 | | /** |
|---|
| 131 | | * Sets the email address that a reading confirmation will be sent. |
|---|
| 132 | | * @var string |
|---|
| 133 | | */ |
|---|
| 134 | | public $ConfirmReadingTo = ""; |
|---|
| 135 | | |
|---|
| 136 | | /** |
|---|
| 137 | | * Sets the hostname to use in Message-Id and Received headers |
|---|
| 138 | | * and as default HELO string. If empty, the value returned |
|---|
| 139 | | * by SERVER_NAME is used or 'localhost.localdomain'. |
|---|
| 140 | | * @var string |
|---|
| 141 | | */ |
|---|
| 142 | | public $Hostname = ""; |
|---|
| 143 | | |
|---|
| 144 | | ///////////////////////////////////////////////// |
|---|
| 145 | | // SMTP VARIABLES |
|---|
| 146 | | ///////////////////////////////////////////////// |
|---|
| 147 | | |
|---|
| 148 | | /** |
|---|
| 149 | | * Sets the SMTP hosts. All hosts must be separated by a |
|---|
| 150 | | * semicolon. You can also specify a different port |
|---|
| 151 | | * for each host by using this format: [hostname:port] |
|---|
| 152 | | * (e.g. "smtp1.example.com:25;smtp2.example.com"). |
|---|
| 153 | | * Hosts will be tried in order. |
|---|
| 154 | | * @var string |
|---|
| 155 | | */ |
|---|
| 156 | | public $Host = "localhost"; |
|---|
| 157 | | |
|---|
| 158 | | /** |
|---|
| 159 | | * Sets the default SMTP server port. |
|---|
| 160 | | * @var int |
|---|
| 161 | | */ |
|---|
| 162 | | public $Port = 25; |
|---|
| 163 | | |
|---|
| 164 | | /** |
|---|
| 165 | | * Sets the SMTP HELO of the message (Default is $Hostname). |
|---|
| 166 | | * @var string |
|---|
| 167 | | */ |
|---|
| 168 | | public $Helo = ""; |
|---|
| 169 | | |
|---|
| 170 | | /** |
|---|
| 171 | | * Sets SMTP authentication. Utilizes the Username and Password variables. |
|---|
| 172 | | * @var bool |
|---|
| 173 | | */ |
|---|
| 174 | | public $SMTPAuth = false; |
|---|
| 175 | | |
|---|
| 176 | | /** |
|---|
| 177 | | * Sets SMTP username. |
|---|
| 178 | | * @var string |
|---|
| 179 | | */ |
|---|
| 180 | | public $Username = ""; |
|---|
| 181 | | |
|---|
| 182 | | /** |
|---|
| 183 | | * Sets SMTP password. |
|---|
| 184 | | * @var string |
|---|
| 185 | | */ |
|---|
| 186 | | public $Password = ""; |
|---|
| 187 | | |
|---|
| 188 | | /** |
|---|
| 189 | | * Sets the SMTP server timeout in seconds. This function will not |
|---|
| 190 | | * work with the win32 version. |
|---|
| 191 | | * @var int |
|---|
| 192 | | */ |
|---|
| 193 | | public $Timeout = 10; |
|---|
| 194 | | |
|---|
| 195 | | /** |
|---|
| 196 | | * Sets SMTP class debugging on or off. |
|---|
| 197 | | * @var bool |
|---|
| 198 | | */ |
|---|
| 199 | | public $SMTPDebug = false; |
|---|
| 200 | | |
|---|
| 201 | | /** |
|---|
| 202 | | * Prevents the SMTP connection from being closed after each mail |
|---|
| 203 | | * sending. If this is set to true then to close the connection |
|---|
| 204 | | * requires an explicit call to SmtpClose(). |
|---|
| 205 | | * @var bool |
|---|
| 206 | | */ |
|---|
| 207 | | public $SMTPKeepAlive = false; |
|---|
| 208 | | |
|---|
| 209 | | /**#@+ |
|---|
| 210 | | * @access private |
|---|
| 211 | | */ |
|---|
| 212 | | protected $smtp = NULL; |
|---|
| 213 | | protected $to = array(); |
|---|
| 214 | | protected $cc = array(); |
|---|
| 215 | | protected $bcc = array(); |
|---|
| 216 | | protected $ReplyTo = array(); |
|---|
| 217 | | protected $attachment = array(); |
|---|
| 218 | | protected $CustomHeader = array(); |
|---|
| 219 | | protected $message_type = ""; |
|---|
| 220 | | protected $boundary = array(); |
|---|
| 221 | | protected $language = array(); |
|---|
| 222 | | protected $error_count = 0; |
|---|
| 223 | | protected $LE = "\n"; |
|---|
| 224 | | /**#@-*/ |
|---|
| 225 | | |
|---|
| 226 | | |
|---|
| | 44 | protected $lang; |
|---|
| 251 | | ///////////////////////////////////////////////// |
|---|
| 252 | | // VARIABLE METHODS |
|---|
| 253 | | ///////////////////////////////////////////////// |
|---|
| 254 | | |
|---|
| 255 | | /** |
|---|
| 256 | | * Sets message type to HTML. |
|---|
| 257 | | * @param bool $bool |
|---|
| 258 | | * @return void |
|---|
| 259 | | */ |
|---|
| 260 | | function IsHTML($bool) { |
|---|
| 261 | | if($bool == true) |
|---|
| 262 | | $this->ContentType = "text/html"; |
|---|
| 263 | | else |
|---|
| 264 | | $this->ContentType = "text/plain"; |
|---|
| 265 | | } |
|---|
| 266 | | |
|---|
| 267 | | /** |
|---|
| 268 | | * Sets Mailer to send message using SMTP. |
|---|
| 269 | | * @return void |
|---|
| 270 | | */ |
|---|
| 271 | | function IsSMTP() { |
|---|
| 272 | | $this->Mailer = "smtp"; |
|---|
| 273 | | } |
|---|
| 274 | | |
|---|
| 275 | | /** |
|---|
| 276 | | * Sets Mailer to send message using PHP mail() function. |
|---|
| 277 | | * @return void |
|---|
| 278 | | */ |
|---|
| 279 | | function IsMail() { |
|---|
| 280 | | $this->Mailer = "mail"; |
|---|
| 281 | | } |
|---|
| 282 | | |
|---|
| 283 | | /** |
|---|
| 284 | | * Sets Mailer to send message using the $Sendmail program. |
|---|
| 285 | | * @return void |
|---|
| 286 | | */ |
|---|
| 287 | | function IsSendmail() { |
|---|
| 288 | | $this->Mailer = "sendmail"; |
|---|
| 289 | | } |
|---|
| 290 | | |
|---|
| 291 | | /** |
|---|
| 292 | | * Sets Mailer to send message using the qmail MTA. |
|---|
| 293 | | * @return void |
|---|
| 294 | | */ |
|---|
| 295 | | function IsQmail() { |
|---|
| 296 | | $this->Sendmail = "/var/qmail/bin/sendmail"; |
|---|
| 297 | | $this->Mailer = "sendmail"; |
|---|
| 298 | | } |
|---|
| 299 | | |
|---|
| 300 | | |
|---|
| 301 | | ///////////////////////////////////////////////// |
|---|
| 302 | | // RECIPIENT METHODS |
|---|
| 303 | | ///////////////////////////////////////////////// |
|---|
| 304 | | |
|---|
| 305 | | /** |
|---|
| 306 | | * Adds a "To" address. |
|---|
| 307 | | * @param string $address |
|---|
| 308 | | * @param string $name |
|---|
| 309 | | * @return void |
|---|
| 310 | | */ |
|---|
| 311 | | function AddAddress($address, $name = "") { |
|---|
| 312 | | $cur = count($this->to); |
|---|
| 313 | | $this->to[$cur][0] = trim($address); |
|---|
| 314 | | $this->to[$cur][1] = $name; |
|---|
| 315 | | } |
|---|
| 316 | | |
|---|
| 317 | | /** |
|---|
| 318 | | * Adds a "Cc" address. Note: this function works |
|---|
| 319 | | * with the SMTP mailer on win32, not with the "mail" |
|---|
| 320 | | * mailer. |
|---|
| 321 | | * @param string $address |
|---|
| 322 | | * @param string $name |
|---|
| 323 | | * @return void |
|---|
| 324 | | */ |
|---|
| 325 | | function AddCC($address, $name = "") { |
|---|
| 326 | | $cur = count($this->cc); |
|---|
| 327 | | $this->cc[$cur][0] = trim($address); |
|---|
| 328 | | $this->cc[$cur][1] = $name; |
|---|
| 329 | | } |
|---|
| 330 | | |
|---|
| 331 | | /** |
|---|
| 332 | | * Adds a "Bcc" address. Note: this function works |
|---|
| 333 | | * with the SMTP mailer on win32, not with the "mail" |
|---|
| 334 | | * mailer. |
|---|
| 335 | | * @param string $address |
|---|
| 336 | | * @param string $name |
|---|
| 337 | | * @return void |
|---|
| 338 | | */ |
|---|
| 339 | | function AddBCC($address, $name = "") { |
|---|
| 340 | | $cur = count($this->bcc); |
|---|
| 341 | | $this->bcc[$cur][0] = trim($address); |
|---|
| 342 | | $this->bcc[$cur][1] = $name; |
|---|
| 343 | | } |
|---|
| 344 | | |
|---|
| 345 | | /** |
|---|
| 346 | | * Adds a "Reply-to" address. |
|---|
| 347 | | * @param string $address |
|---|
| 348 | | * @param string $name |
|---|
| 349 | | * @return void |
|---|
| 350 | | */ |
|---|
| 351 | | function AddReplyTo($address, $name = "") { |
|---|
| 352 | | $cur = count($this->ReplyTo); |
|---|
| 353 | | $this->ReplyTo[$cur][0] = trim($address); |
|---|
| 354 | | $this->ReplyTo[$cur][1] = $name; |
|---|
| 355 | | } |
|---|
| 356 | | |
|---|
| 357 | | |
|---|
| 519 | | |
|---|
| 520 | | if ($this->Sender != "" && strlen(ini_get("safe_mode"))< 1) |
|---|
| 521 | | { |
|---|
| 522 | | $old_from = ini_get("sendmail_from"); |
|---|
| 523 | | ini_set("sendmail_from", $this->Sender); |
|---|
| 524 | | $params = sprintf("-oi -f %s", $this->Sender); |
|---|
| 525 | | $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, |
|---|
| 526 | | $header, $params); |
|---|
| 527 | | } |
|---|
| 528 | | else |
|---|
| 529 | | $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header); |
|---|
| 530 | | |
|---|
| 531 | | if (isset($old_from)) |
|---|
| 532 | | ini_set("sendmail_from", $old_from); |
|---|
| 533 | | |
|---|
| 534 | | if(!$rt) |
|---|
| 535 | | { |
|---|
| 536 | | throw new jException('jelix~errors.mail.instantiate'); |
|---|
| 537 | | } |
|---|
| 538 | | |
|---|
| 539 | | return true; |
|---|
| 540 | | } |
|---|
| 541 | | |
|---|
| 542 | | /** |
|---|
| 543 | | * Sends mail via SMTP using PhpSMTP (Author: |
|---|
| 544 | | * Chris Ryan). Returns bool. Returns false if there is a |
|---|
| 545 | | * bad MAIL FROM, RCPT, or DATA input. |
|---|
| 546 | | * @return bool |
|---|
| 547 | | */ |
|---|
| 548 | | protected function SmtpSend($header, $body) { |
|---|
| 549 | | require_once(JELIX_LIB_UTILS_PATH.'jSmtp.class.php'); |
|---|
| 550 | | $bad_rcpt = array(); |
|---|
| 551 | | |
|---|
| 552 | | if(!$this->SmtpConnect()) |
|---|
| 553 | | return false; |
|---|
| 554 | | |
|---|
| 555 | | $smtp_from = ($this->Sender == "") ? $this->From : $this->Sender; |
|---|
| 556 | | if(!$this->smtp->Mail($smtp_from)) |
|---|
| 557 | | { |
|---|
| 558 | | $this->smtp->Reset(); |
|---|
| 559 | | throw new jException('jelix~errors.mail.from_failed',$smtp_from); |
|---|
| 560 | | } |
|---|
| 561 | | |
|---|
| 562 | | // Attempt to send attach all recipients |
|---|
| 563 | | for($i = 0; $i < count($this->to); $i++) |
|---|
| 564 | | { |
|---|
| 565 | | if(!$this->smtp->Recipient($this->to[$i][0])) |
|---|
| 566 | | $bad_rcpt[] = $this->to[$i][0]; |
|---|
| 567 | | } |
|---|
| 568 | | for($i = 0; $i < count($this->cc); $i++) |
|---|
| 569 | | { |
|---|
| 570 | | if(!$this->smtp->Recipient($this->cc[$i][0])) |
|---|
| 571 | | $bad_rcpt[] = $this->cc[$i][0]; |
|---|
| 572 | | } |
|---|
| 573 | | for($i = 0; $i < count($this->bcc); $i++) |
|---|
| 574 | | { |
|---|
| 575 | | if(!$this->smtp->Recipient($this->bcc[$i][0])) |
|---|
| 576 | | $bad_rcpt[] = $this->bcc[$i][0]; |
|---|
| 577 | | } |
|---|
| 578 | | |
|---|
| 579 | | if(count($bad_rcpt) > 0) // Create error message |
|---|
| 580 | | { |
|---|
| 581 | | $error = ''; |
|---|
| 582 | | for($i = 0; $i < count($bad_rcpt); $i++) |
|---|
| 583 | | { |
|---|
| 584 | | if($i != 0) { $error .= ", "; } |
|---|
| 585 | | $error .= $bad_rcpt[$i]; |
|---|
| 586 | | } |
|---|
| 587 | | $this->smtp->Reset(); |
|---|
| 588 | | throw new jException('jelix~errors.mail.recipients_failed',$error); |
|---|
| 589 | | } |
|---|
| 590 | | |
|---|
| 591 | | if(!$this->smtp->Data($header . $body)) |
|---|
| 592 | | { |
|---|
| 593 | | |
|---|
| 594 | | $this->smtp->Reset(); |
|---|
| 595 | | throw new jException('jelix~errors.mail.data_not_accepted'); |
|---|
| 596 | | } |
|---|
| 597 | | if($this->SMTPKeepAlive == true) |
|---|
| 598 | | $this->smtp->Reset(); |
|---|
| 599 | | else |
|---|
| 600 | | $this->SmtpClose(); |
|---|
| 601 | | |
|---|
| 602 | | return true; |
|---|
| 603 | | } |
|---|
| 604 | | |
|---|
| 605 | | /** |
|---|
| 606 | | * Initiates a connection to an SMTP server. Returns false if the |
|---|
| 607 | | * operation failed. |
|---|
| 608 | | * @access private |
|---|
| 609 | | * @return bool |
|---|
| 610 | | */ |
|---|
| 611 | | protected function SmtpConnect() { |
|---|
| 612 | | if($this->smtp == NULL) { $this->smtp = new jSmtp(); } |
|---|
| 613 | | |
|---|
| 614 | | $this->smtp->do_debug = $this->SMTPDebug; |
|---|
| 615 | | $hosts = explode(";", $this->Host); |
|---|
| 616 | | $index = 0; |
|---|
| 617 | | $connection = ($this->smtp->Connected()); |
|---|
| 618 | | |
|---|
| 619 | | // Retry while there is no connection |
|---|
| 620 | | while($index < count($hosts) && $connection == false) |
|---|
| 621 | | { |
|---|
| 622 | | if(strstr($hosts[$index], ":")) |
|---|
| 623 | | list($host, $port) = explode(":", $hosts[$index]); |
|---|
| 624 | | else |
|---|
| 625 | | { |
|---|
| 626 | | $host = $hosts[$index]; |
|---|
| 627 | | $port = $this->Port; |
|---|
| 628 | | } |
|---|
| 629 | | |
|---|
| 630 | | if($this->smtp->Connect($host, $port, $this->Timeout)) |
|---|
| 631 | | { |
|---|
| 632 | | if ($this->Helo != '') |
|---|
| 633 | | $this->smtp->Hello($this->Helo); |
|---|
| 634 | | else |
|---|
| 635 | | $this->smtp->Hello($this->ServerHostname()); |
|---|
| 636 | | |
|---|
| 637 | | if($this->SMTPAuth) |
|---|
| 638 | | { |
|---|
| 639 | | if(!$this->smtp->Authenticate($this->Username, |
|---|
| 640 | | $this->Password)) |
|---|
| 641 | | { |
|---|
| 642 | | $this->smtp->Reset(); |
|---|
| 643 | | throw new jException('jelix~errors.mail.authenticate'); |
|---|
| 644 | | } |
|---|
| 645 | | } |
|---|
| 646 | | $connection = true; |
|---|
| 647 | | } |
|---|
| 648 | | $index++; |
|---|
| 649 | | } |
|---|
| 650 | | if(!$connection) |
|---|
| 651 | | throw new jException('jelix~errors.mail.connect_host'); |
|---|
| 652 | | |
|---|
| 653 | | return $connection; |
|---|
| 654 | | } |
|---|
| 655 | | |
|---|
| 656 | | /** |
|---|
| 657 | | * Closes the active SMTP session if one exists. |
|---|
| 658 | | * @return void |
|---|
| 659 | | */ |
|---|
| 660 | | public function SmtpClose() { |
|---|
| 661 | | if($this->smtp != NULL) |
|---|
| 662 | | { |
|---|
| 663 | | if($this->smtp->Connected()) |
|---|
| 664 | | { |
|---|
| 665 | | $this->smtp->Quit(); |
|---|
| 666 | | $this->smtp->Close(); |
|---|
| 667 | | } |
|---|
| 668 | | } |
|---|
| 669 | | } |
|---|
| 670 | | |
|---|
| 671 | | ///////////////////////////////////////////////// |
|---|
| 672 | | // MESSAGE CREATION METHODS |
|---|
| 673 | | ///////////////////////////////////////////////// |
|---|
| 674 | | |
|---|
| 675 | | /** |
|---|
| 676 | | * Creates recipient headers. |
|---|
| 677 | | * @return string |
|---|
| 678 | | */ |
|---|
| 679 | | protected function AddrAppend($type, $addr) { |
|---|
| 680 | | $addr_str = $type . ": "; |
|---|
| 681 | | $addr_str .= $this->AddrFormat($addr[0]); |
|---|
| 682 | | if(count($addr) > 1) |
|---|
| 683 | | { |
|---|
| 684 | | for($i = 1; $i < count($addr); $i++) |
|---|
| 685 | | $addr_str .= ", " . $this->AddrFormat($addr[$i]); |
|---|
| 686 | | } |
|---|
| 687 | | $addr_str .= $this->LE; |
|---|
| 688 | | |
|---|
| 689 | | return $addr_str; |
|---|
| 690 | | } |
|---|
| 691 | | |
|---|
| 692 | | /** |
|---|
| 693 | | * Formats an address correctly. |
|---|
| 694 | | * @return string |
|---|
| 695 | | */ |
|---|
| 696 | | protected function AddrFormat($addr) { |
|---|
| 697 | | if(empty($addr[1])) |
|---|
| 698 | | $formatted = $addr[0]; |
|---|
| 699 | | else |
|---|
| 700 | | { |
|---|
| 701 | | $formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" . |
|---|
| 702 | | $addr[0] . ">"; |
|---|
| 703 | | } |
|---|
| 704 | | |
|---|
| 705 | | return $formatted; |
|---|
| 706 | | } |
|---|
| 707 | | |
|---|
| 708 | | /** |
|---|
| 709 | | * Wraps message for use with mailers that do not |
|---|
| 710 | | * automatically perform wrapping and for quoted-printable. |
|---|
| 711 | | * Original written by philippe. |
|---|
| 712 | | * @internal the code of this method has been picked from version 2.0.0 og PHPMailer |
|---|
| 713 | | * @return string |
|---|
| 714 | | */ |
|---|
| 715 | | protected function WrapText($message, $length, $qp_mode = false) { |
|---|
| 716 | | $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE; |
|---|
| 717 | | |
|---|
| 718 | | $message = $this->FixEOL($message); |
|---|
| 719 | | if (substr($message, -1) == $this->LE) { |
|---|
| 720 | | $message = substr($message, 0, -1); |
|---|
| 721 | | } |
|---|
| 722 | | |
|---|
| 723 | | $line = explode($this->LE, $message); |
|---|
| 724 | | $message = ''; |
|---|
| 725 | | for ($i=0 ;$i < count($line); $i++) { |
|---|
| 726 | | $line_part = explode(' ', $line[$i]); |
|---|
| 727 | | $buf = ''; |
|---|
| 728 | | for ($e = 0; $e<count($line_part); $e++) { |
|---|
| 729 | | $word = $line_part[$e]; |
|---|
| 730 | | if ($qp_mode and (strlen($word) > $length)) { |
|---|
| 731 | | $space_left = $length - strlen($buf) - 1; |
|---|
| 732 | | if ($e != 0) { |
|---|
| 733 | | if ($space_left > 20) { |
|---|
| 734 | | $len = $space_left; |
|---|
| 735 | | if (substr($word, $len - 1, 1) == '=') { |
|---|
| 736 | | $len--; |
|---|
| 737 | | } elseif (substr($word, $len - 2, 1) == '=') { |
|---|
| 738 | | $len -= 2; |
|---|
| 739 | | } |
|---|
| 740 | | $part = substr($word, 0, $len); |
|---|
| 741 | | $word = substr($word, $len); |
|---|
| 742 | | $buf .= ' ' . $part; |
|---|
| 743 | | $message .= $buf . sprintf("=%s", $this->LE); |
|---|
| 744 | | } else { |
|---|
| 745 | | $message .= $buf . $soft_break; |
|---|
| 746 | | } |
|---|
| 747 | | $buf = ''; |
|---|
| 748 | | } |
|---|
| 749 | | while (strlen($word) > 0) { |
|---|
| 750 | | $len = $length; |
|---|
| 751 | | if (substr($word, $len - 1, 1) == '=') { |
|---|
| 752 | | $len--; |
|---|
| 753 | | } elseif (substr($word, $len - 2, 1) == '=') { |
|---|
| 754 | | $len -= 2; |
|---|
| 755 | | } |
|---|
| 756 | | $part = substr($word, 0, $len); |
|---|
| 757 | | $word = substr($word, $len); |
|---|
| 758 | | |
|---|
| 759 | | if (strlen($word) > 0) { |
|---|
| 760 | | $message .= $part . sprintf("=%s", $this->LE); |
|---|
| 761 | | } else { |
|---|
| 762 | | $buf = $part; |
|---|
| 763 | | } |
|---|
| 764 | | } |
|---|
| 765 | | } else { |
|---|
| 766 | | $buf_o = $buf; |
|---|
| 767 | | $buf .= ($e == 0) ? $word : (' ' . $word); |
|---|
| 768 | | |
|---|
| 769 | | if (strlen($buf) > $length and $buf_o != '') { |
|---|
| 770 | | $message .= $buf_o . $soft_break; |
|---|
| 771 | | $buf = $word; |
|---|
| 772 | | } |
|---|
| 773 | | } |
|---|
| 774 | | } |
|---|
| 775 | | $message .= $buf . $this->LE; |
|---|
| 776 | | } |
|---|
| 777 | | |
|---|
| 778 | | return $message; |
|---|
| 779 | | } |
|---|
| 780 | | |
|---|
| 781 | | /** |
|---|
| 782 | | * Set the body wrapping. |
|---|
| 783 | | * @return void |
|---|
| 784 | | */ |
|---|
| 785 | | protected function SetWordWrap() { |
|---|
| 786 | | if($this->WordWrap < 1) |
|---|
| 787 | | return; |
|---|
| 788 | | |
|---|
| 789 | | switch($this->message_type) |
|---|
| 790 | | { |
|---|
| 791 | | case "alt": |
|---|
| 792 | | // fall through |
|---|
| 793 | | case "alt_attachments": |
|---|
| 794 | | $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); |
|---|
| 795 | | break; |
|---|
| 796 | | default: |
|---|
| 797 | | $this->Body = $this->WrapText($this->Body, $this->WordWrap); |
|---|
| 798 | | break; |
|---|
| | 181 | else { |
|---|
| | 182 | throw new Exception($msg); |
|---|
| 803 | | * Assembles message header. |
|---|
| 804 | | * @return string |
|---|
| 805 | | */ |
|---|
| 806 | | protected function CreateHeader() { |
|---|
| 807 | | $result = ""; |
|---|
| 808 | | |
|---|
| 809 | | // Set the boundaries |
|---|
| 810 | | $uniq_id = md5(uniqid(time())); |
|---|
| 811 | | $this->boundary[1] = "b1_" . $uniq_id; |
|---|
| 812 | | $this->boundary[2] = "b2_" . $uniq_id; |
|---|
| 813 | | |
|---|
| 814 | | $result .= $this->HeaderLine("Date", $this->RFCDate()); |
|---|
| 815 | | if($this->Sender == "") |
|---|
| 816 | | $result .= $this->HeaderLine("Return-Path", trim($this->From)); |
|---|
| 817 | | else |
|---|
| 818 | | $result .= $this->HeaderLine("Return-Path", trim($this->Sender)); |
|---|
| 819 | | |
|---|
| 820 | | // To be created automatically by mail() |
|---|
| 821 | | if($this->Mailer != "mail") |
|---|
| 822 | | { |
|---|
| 823 | | if(count($this->to) > 0) |
|---|
| 824 | | $result .= $this->AddrAppend("To", $this->to); |
|---|
| 825 | | else if (count($this->cc) == 0) |
|---|
| 826 | | $result .= $this->HeaderLine("To", "undisclosed-recipients:;"); |
|---|
| 827 | | if(count($this->cc) > 0) |
|---|
| 828 | | $result .= $this->AddrAppend("Cc", $this->cc); |
|---|
| 829 | | } |
|---|
| 830 | | |
|---|
| 831 | | $from = array(); |
|---|
| 832 | | $from[0][0] = trim($this->From); |
|---|
| 833 | | $from[0][1] = $this->FromName; |
|---|
| 834 | | $result .= $this->AddrAppend("From", $from); |
|---|
| 835 | | |
|---|
| 836 | | // sendmail and mail() extract Bcc from the header before sending |
|---|
| 837 | | if((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && (count($this->bcc) > 0)) |
|---|
| 838 | | $result .= $this->AddrAppend("Bcc", $this->bcc); |
|---|
| 839 | | |
|---|
| 840 | | if(count($this->ReplyTo) > 0) |
|---|
| 841 | | $result .= $this->AddrAppend("Reply-to", $this->ReplyTo); |
|---|
| 842 | | |
|---|
| 843 | | // mail() sets the subject itself |
|---|
| 844 | | if($this->Mailer != "mail") |
|---|
| 845 | | $result .= $this->HeaderLine("Subject", $this->EncodeHeader(trim($this->Subject))); |
|---|
| 846 | | |
|---|
| 847 | | $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); |
|---|
| 848 | | $result .= $this->HeaderLine("X-Priority", $this->Priority); |
|---|
| 849 | | $result .= $this->HeaderLine("X-Mailer", "PHPMailer [version " . $this->Version . "]"); |
|---|
| 850 | | |
|---|
| 851 | | if($this->ConfirmReadingTo != "") |
|---|
| 852 | | { |
|---|
| 853 | | $result .= $this->HeaderLine("Disposition-Notification-To", |
|---|
| 854 | | "<" . trim($this->ConfirmReadingTo) . ">"); |
|---|
| 855 | | } |
|---|
| 856 | | |
|---|
| 857 | | // Add custom headers |
|---|
| 858 | | for($index = 0; $index < count($this->CustomHeader); $index++) |
|---|
| 859 | | { |
|---|
| 860 | | $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), |
|---|
| 861 | | $this->EncodeHeader(trim($this->CustomHeader[$index][1]))); |
|---|
| 862 | | } |
|---|
| 863 | | $result .= $this->HeaderLine("MIME-Version", "1.0"); |
|---|
| 864 | | |
|---|
| 865 | | switch($this->message_type) |
|---|
| 866 | | { |
|---|
| 867 | | case "plain": |
|---|
| 868 | | $result .= $this->HeaderLine("Content-Transfer-Encoding", $this->Encoding); |
|---|
| 869 | | $result .= sprintf("Content-Type: %s; charset=\"%s\"", |
|---|
| 870 | | $this->ContentType, $this->CharSet); |
|---|
| 871 | | break; |
|---|
| 872 | | case "attachments": |
|---|
| 873 | | // fall through |
|---|
| 874 | | &n |
|---|