PageRenderTime 9ms CodeModel.GetById 5ms app.highlight 34ms RepoModel.GetById 1ms app.codeStats 1ms

/vendor/PHPMailer/class.phpmailer.php

https://github.com/scogle/cockpit
PHP | 3419 lines | 2005 code | 230 blank | 1184 comment | 344 complexity | 48552a8e0d5d7dae7d6f855bf19f8e50 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2/**
   3 * PHPMailer - PHP email creation and transport class.
   4 * PHP Version 5
   5 * @package PHPMailer
   6 * @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
   7 * @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
   8 * @author Jim Jagielski (jimjag) <jimjag@gmail.com>
   9 * @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
  10 * @author Brent R. Matzelle (original founder)
  11 * @copyright 2012 - 2014 Marcus Bointon
  12 * @copyright 2010 - 2012 Jim Jagielski
  13 * @copyright 2004 - 2009 Andy Prevost
  14 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  15 * @note This program is distributed in the hope that it will be useful - WITHOUT
  16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  17 * FITNESS FOR A PARTICULAR PURPOSE.
  18 */
  19
  20/**
  21 * PHPMailer - PHP email creation and transport class.
  22 * @package PHPMailer
  23 * @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
  24 * @author Jim Jagielski (jimjag) <jimjag@gmail.com>
  25 * @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
  26 * @author Brent R. Matzelle (original founder)
  27 */
  28class PHPMailer
  29{
  30    /**
  31     * The PHPMailer Version number.
  32     * @type string
  33     */
  34    public $Version = '5.2.7';
  35
  36    /**
  37     * Email priority.
  38     * Options: 1 = High, 3 = Normal, 5 = low.
  39     * @type int
  40     */
  41    public $Priority = 3;
  42
  43    /**
  44     * The character set of the message.
  45     * @type string
  46     */
  47    public $CharSet = 'iso-8859-1';
  48
  49    /**
  50     * The MIME Content-type of the message.
  51     * @type string
  52     */
  53    public $ContentType = 'text/plain';
  54
  55    /**
  56     * The message encoding.
  57     * Options: "8bit", "7bit", "binary", "base64", and "quoted-printable".
  58     * @type string
  59     */
  60    public $Encoding = '8bit';
  61
  62    /**
  63     * Holds the most recent mailer error message.
  64     * @type string
  65     */
  66    public $ErrorInfo = '';
  67
  68    /**
  69     * The From email address for the message.
  70     * @type string
  71     */
  72    public $From = 'root@localhost';
  73
  74    /**
  75     * The From name of the message.
  76     * @type string
  77     */
  78    public $FromName = 'Root User';
  79
  80    /**
  81     * The Sender email (Return-Path) of the message.
  82     * If not empty, will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
  83     * @type string
  84     */
  85    public $Sender = '';
  86
  87    /**
  88     * The Return-Path of the message.
  89     * If empty, it will be set to either From or Sender.
  90     * @type string
  91     * @deprecated Email senders should never set a return-path header;
  92     * it's the receiver's job (RFC5321 section 4.4), so this no longer does anything.
  93     * @link https://tools.ietf.org/html/rfc5321#section-4.4 RFC5321 reference
  94     */
  95    public $ReturnPath = '';
  96
  97    /**
  98     * The Subject of the message.
  99     * @type string
 100     */
 101    public $Subject = '';
 102
 103    /**
 104     * An HTML or plain text message body.
 105     * If HTML then call isHTML(true).
 106     * @type string
 107     */
 108    public $Body = '';
 109
 110    /**
 111     * The plain-text message body.
 112     * This body can be read by mail clients that do not have HTML email
 113     * capability such as mutt & Eudora.
 114     * Clients that can read HTML will view the normal Body.
 115     * @type string
 116     */
 117    public $AltBody = '';
 118
 119    /**
 120     * An iCal message part body.
 121     * Only supported in simple alt or alt_inline message types
 122     * To generate iCal events, use the bundled extras/EasyPeasyICS.php class or iCalcreator
 123     * @link http://sprain.ch/blog/downloads/php-class-easypeasyics-create-ical-files-with-php/
 124     * @link http://kigkonsult.se/iCalcreator/
 125     * @type string
 126     */
 127    public $Ical = '';
 128
 129    /**
 130     * The complete compiled MIME message body.
 131     * @access protected
 132     * @type string
 133     */
 134    protected $MIMEBody = '';
 135
 136    /**
 137     * The complete compiled MIME message headers.
 138     * @type string
 139     * @access protected
 140     */
 141    protected $MIMEHeader = '';
 142
 143    /**
 144     * Extra headers that createHeader() doesn't fold in.
 145     * @type string
 146     * @access protected
 147     */
 148    protected $mailHeader = '';
 149
 150    /**
 151     * Word-wrap the message body to this number of chars.
 152     * @type int
 153     */
 154    public $WordWrap = 0;
 155
 156    /**
 157     * Which method to use to send mail.
 158     * Options: "mail", "sendmail", or "smtp".
 159     * @type string
 160     */
 161    public $Mailer = 'mail';
 162
 163    /**
 164     * The path to the sendmail program.
 165     * @type string
 166     */
 167    public $Sendmail = '/usr/sbin/sendmail';
 168
 169    /**
 170     * Whether mail() uses a fully sendmail-compatible MTA.
 171     * One which supports sendmail's "-oi -f" options.
 172     * @type bool
 173     */
 174    public $UseSendmailOptions = true;
 175
 176    /**
 177     * Path to PHPMailer plugins.
 178     * Useful if the SMTP class is not in the PHP include path.
 179     * @type string
 180     * @deprecated Should not be needed now there is an autoloader.
 181     */
 182    public $PluginDir = '';
 183
 184    /**
 185     * The email address that a reading confirmation should be sent to.
 186     * @type string
 187     */
 188    public $ConfirmReadingTo = '';
 189
 190    /**
 191     * The hostname to use in Message-Id and Received headers
 192     * and as default HELO string.
 193     * If empty, the value returned
 194     * by SERVER_NAME is used or 'localhost.localdomain'.
 195     * @type string
 196     */
 197    public $Hostname = '';
 198
 199    /**
 200     * An ID to be used in the Message-Id header.
 201     * If empty, a unique id will be generated.
 202     * @type string
 203     */
 204    public $MessageID = '';
 205
 206    /**
 207     * The message Date to be used in the Date header.
 208     * If empty, the current date will be added.
 209     * @type string
 210     */
 211    public $MessageDate = '';
 212
 213    /**
 214     * SMTP hosts.
 215     * Either a single hostname or multiple semicolon-delimited hostnames.
 216     * You can also specify a different port
 217     * for each host by using this format: [hostname:port]
 218     * (e.g. "smtp1.example.com:25;smtp2.example.com").
 219     * Hosts will be tried in order.
 220     * @type string
 221     */
 222    public $Host = 'localhost';
 223
 224    /**
 225     * The default SMTP server port.
 226     * @type int
 227     * @Todo Why is this needed when the SMTP class takes care of it?
 228     */
 229    public $Port = 25;
 230
 231    /**
 232     * The SMTP HELO of the message.
 233     * Default is $Hostname.
 234     * @type string
 235     * @see PHPMailer::$Hostname
 236     */
 237    public $Helo = '';
 238
 239    /**
 240     * The secure connection prefix.
 241     * Options: "", "ssl" or "tls"
 242     * @type string
 243     */
 244    public $SMTPSecure = '';
 245
 246    /**
 247     * Whether to use SMTP authentication.
 248     * Uses the Username and Password properties.
 249     * @type bool
 250     * @see PHPMailer::$Username
 251     * @see PHPMailer::$Password
 252     */
 253    public $SMTPAuth = false;
 254
 255    /**
 256     * SMTP username.
 257     * @type string
 258     */
 259    public $Username = '';
 260
 261    /**
 262     * SMTP password.
 263     * @type string
 264     */
 265    public $Password = '';
 266
 267    /**
 268     * SMTP auth type.
 269     * Options are LOGIN (default), PLAIN, NTLM, CRAM-MD5
 270     * @type string
 271     */
 272    public $AuthType = '';
 273
 274    /**
 275     * SMTP realm.
 276     * Used for NTLM auth
 277     * @type string
 278     */
 279    public $Realm = '';
 280
 281    /**
 282     * SMTP workstation.
 283     * Used for NTLM auth
 284     * @type string
 285     */
 286    public $Workstation = '';
 287
 288    /**
 289     * The SMTP server timeout in seconds.
 290     * @type int
 291     */
 292    public $Timeout = 10;
 293
 294    /**
 295     * SMTP class debug output mode.
 296     * Options:
 297     *   0: no output
 298     *   1: commands
 299     *   2: data and commands
 300     *   3: as 2 plus connection status
 301     *   4: low level data output
 302     * @type int
 303     * @see SMTP::$do_debug
 304     */
 305    public $SMTPDebug = 0;
 306
 307    /**
 308     * How to handle debug output.
 309     * Options:
 310     *   'echo': Output plain-text as-is, appropriate for CLI
 311     *   'html': Output escaped, line breaks converted to <br>, appropriate for browser output
 312     *   'error_log': Output to error log as configured in php.ini
 313     * @type string
 314     * @see SMTP::$Debugoutput
 315     */
 316    public $Debugoutput = 'echo';
 317
 318    /**
 319     * Whether to keep SMTP connection open after each message.
 320     * If this is set to true then to close the connection
 321     * requires an explicit call to smtpClose().
 322     * @type bool
 323     */
 324    public $SMTPKeepAlive = false;
 325
 326    /**
 327     * Whether to split multiple to addresses into multiple messages
 328     * or send them all in one message.
 329     * @type bool
 330     */
 331    public $SingleTo = false;
 332
 333    /**
 334     * Storage for addresses when SingleTo is enabled.
 335     * @type array
 336     * @todo This should really not be public
 337     */
 338    public $SingleToArray = array();
 339
 340    /**
 341     * Whether to generate VERP addresses on send.
 342     * Only applicable when sending via SMTP.
 343     * @link http://en.wikipedia.org/wiki/Variable_envelope_return_path
 344     * @link http://www.postfix.org/VERP_README.html Postfix VERP info
 345     * @type bool
 346     */
 347    public $do_verp = false;
 348
 349    /**
 350     * Whether to allow sending messages with an empty body.
 351     * @type bool
 352     */
 353    public $AllowEmpty = false;
 354
 355    /**
 356     * The default line ending.
 357     * @note The default remains "\n". We force CRLF where we know
 358     *        it must be used via self::CRLF.
 359     * @type string
 360     */
 361    public $LE = "\n";
 362
 363    /**
 364     * DKIM selector.
 365     * @type string
 366     */
 367    public $DKIM_selector = '';
 368
 369    /**
 370     * DKIM Identity.
 371     * Usually the email address used as the source of the email
 372     * @type string
 373     */
 374    public $DKIM_identity = '';
 375
 376    /**
 377     * DKIM passphrase.
 378     * Used if your key is encrypted.
 379     * @type string
 380     */
 381    public $DKIM_passphrase = '';
 382
 383    /**
 384     * DKIM signing domain name.
 385     * @example 'example.com'
 386     * @type string
 387     */
 388    public $DKIM_domain = '';
 389
 390    /**
 391     * DKIM private key file path.
 392     * @type string
 393     */
 394    public $DKIM_private = '';
 395
 396    /**
 397     * Callback Action function name.
 398     *
 399     * The function that handles the result of the send email action.
 400     * It is called out by send() for each email sent.
 401     *
 402     * Value can be any php callable: http://www.php.net/is_callable
 403     *
 404     * Parameters:
 405     *   bool    $result        result of the send action
 406     *   string  $to            email address of the recipient
 407     *   string  $cc            cc email addresses
 408     *   string  $bcc           bcc email addresses
 409     *   string  $subject       the subject
 410     *   string  $body          the email body
 411     *   string  $from          email address of sender
 412     * @type string
 413     */
 414    public $action_function = '';
 415
 416    /**
 417     * What to use in the X-Mailer header.
 418     * Options: null for default, whitespace for none, or a string to use
 419     * @type string
 420     */
 421    public $XMailer = '';
 422
 423    /**
 424     * An instance of the SMTP sender class.
 425     * @type SMTP
 426     * @access protected
 427     */
 428    protected $smtp = null;
 429
 430    /**
 431     * The array of 'to' addresses.
 432     * @type array
 433     * @access protected
 434     */
 435    protected $to = array();
 436
 437    /**
 438     * The array of 'cc' addresses.
 439     * @type array
 440     * @access protected
 441     */
 442    protected $cc = array();
 443
 444    /**
 445     * The array of 'bcc' addresses.
 446     * @type array
 447     * @access protected
 448     */
 449    protected $bcc = array();
 450
 451    /**
 452     * The array of reply-to names and addresses.
 453     * @type array
 454     * @access protected
 455     */
 456    protected $ReplyTo = array();
 457
 458    /**
 459     * An array of all kinds of addresses.
 460     * Includes all of $to, $cc, $bcc, $replyto
 461     * @type array
 462     * @access protected
 463     */
 464    protected $all_recipients = array();
 465
 466    /**
 467     * The array of attachments.
 468     * @type array
 469     * @access protected
 470     */
 471    protected $attachment = array();
 472
 473    /**
 474     * The array of custom headers.
 475     * @type array
 476     * @access protected
 477     */
 478    protected $CustomHeader = array();
 479
 480    /**
 481     * The most recent Message-ID (including angular brackets).
 482     * @type string
 483     * @access protected
 484     */
 485    protected $lastMessageID = '';
 486
 487    /**
 488     * The message's MIME type.
 489     * @type string
 490     * @access protected
 491     */
 492    protected $message_type = '';
 493
 494    /**
 495     * The array of MIME boundary strings.
 496     * @type array
 497     * @access protected
 498     */
 499    protected $boundary = array();
 500
 501    /**
 502     * The array of available languages.
 503     * @type array
 504     * @access protected
 505     */
 506    protected $language = array();
 507
 508    /**
 509     * The number of errors encountered.
 510     * @type integer
 511     * @access protected
 512     */
 513    protected $error_count = 0;
 514
 515    /**
 516     * The S/MIME certificate file path.
 517     * @type string
 518     * @access protected
 519     */
 520    protected $sign_cert_file = '';
 521
 522    /**
 523     * The S/MIME key file path.
 524     * @type string
 525     * @access protected
 526     */
 527    protected $sign_key_file = '';
 528
 529    /**
 530     * The S/MIME password for the key.
 531     * Used only if the key is encrypted.
 532     * @type string
 533     * @access protected
 534     */
 535    protected $sign_key_pass = '';
 536
 537    /**
 538     * Whether to throw exceptions for errors.
 539     * @type bool
 540     * @access protected
 541     */
 542    protected $exceptions = false;
 543
 544    /**
 545     * Error severity: message only, continue processing
 546     */
 547    const STOP_MESSAGE = 0;
 548
 549    /**
 550     * Error severity: message, likely ok to continue processing
 551     */
 552    const STOP_CONTINUE = 1;
 553
 554    /**
 555     * Error severity: message, plus full stop, critical error reached
 556     */
 557    const STOP_CRITICAL = 2;
 558
 559    /**
 560     * SMTP RFC standard line ending
 561     */
 562    const CRLF = "\r\n";
 563
 564    /**
 565     * Constructor
 566     * @param bool $exceptions Should we throw external exceptions?
 567     */
 568    public function __construct($exceptions = false)
 569    {
 570        if (version_compare(PHP_VERSION, '5.0.0', '<')) {
 571            exit("Sorry, PHPMailer will only run on PHP version 5 or greater!\n");
 572        }
 573        $this->exceptions = ($exceptions == true);
 574        //Make sure our autoloader is loaded
 575        if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
 576            $autoload = spl_autoload_functions();
 577            if ($autoload === false or !in_array('PHPMailerAutoload', $autoload)) {
 578                require 'PHPMailerAutoload.php';
 579            }
 580        }
 581    }
 582
 583    /**
 584     * Destructor.
 585     */
 586    public function __destruct()
 587    {
 588        if ($this->Mailer == 'smtp') { //close any open SMTP connection nicely
 589            $this->smtpClose();
 590        }
 591    }
 592
 593    /**
 594     * Call mail() in a safe_mode-aware fashion.
 595     * Also, unless sendmail_path points to sendmail (or something that
 596     * claims to be sendmail), don't pass params (not a perfect fix,
 597     * but it will do)
 598     * @param string $to To
 599     * @param string $subject Subject
 600     * @param string $body Message Body
 601     * @param string $header Additional Header(s)
 602     * @param string $params Params
 603     * @access private
 604     * @return bool
 605     */
 606    private function mailPassthru($to, $subject, $body, $header, $params)
 607    {
 608        //Check overloading of mail function to avoid double-encoding
 609        if (ini_get('mbstring.func_overload') & 1) {
 610            $subject = $this->secureHeader($subject);
 611        } else {
 612            $subject = $this->encodeHeader($this->secureHeader($subject));
 613        }
 614        if (ini_get('safe_mode') || !($this->UseSendmailOptions)) {
 615            $result = @mail($to, $subject, $body, $header);
 616        } else {
 617            $result = @mail($to, $subject, $body, $header, $params);
 618        }
 619        return $result;
 620    }
 621
 622    /**
 623     * Output debugging info via user-defined method.
 624     * Only if debug output is enabled.
 625     * @see PHPMailer::$Debugoutput
 626     * @see PHPMailer::$SMTPDebug
 627     * @param string $str
 628     */
 629    protected function edebug($str)
 630    {
 631        if (!$this->SMTPDebug) {
 632            return;
 633        }
 634        switch ($this->Debugoutput) {
 635            case 'error_log':
 636                error_log($str);
 637                break;
 638            case 'html':
 639                //Cleans up output a bit for a better looking display that's HTML-safe
 640                echo htmlentities(preg_replace('/[\r\n]+/', '', $str), ENT_QUOTES, $this->CharSet) . "<br>\n";
 641                break;
 642            case 'echo':
 643            default:
 644                echo $str."\n";
 645        }
 646    }
 647
 648    /**
 649     * Sets message type to HTML or plain.
 650     * @param bool $ishtml True for HTML mode.
 651     * @return void
 652     */
 653    public function isHTML($ishtml = true)
 654    {
 655        if ($ishtml) {
 656            $this->ContentType = 'text/html';
 657        } else {
 658            $this->ContentType = 'text/plain';
 659        }
 660    }
 661
 662    /**
 663     * Send messages using SMTP.
 664     * @return void
 665     */
 666    public function isSMTP()
 667    {
 668        $this->Mailer = 'smtp';
 669    }
 670
 671    /**
 672     * Send messages using PHP's mail() function.
 673     * @return void
 674     */
 675    public function isMail()
 676    {
 677        $this->Mailer = 'mail';
 678    }
 679
 680    /**
 681     * Send messages using $Sendmail.
 682     * @return void
 683     */
 684    public function isSendmail()
 685    {
 686        $ini_sendmail_path = ini_get('sendmail_path');
 687        
 688        if (!stristr($ini_sendmail_path, 'sendmail')) {
 689            $this->Sendmail = '/usr/sbin/sendmail';
 690        } else {
 691            $this->Sendmail = $ini_sendmail_path;
 692        }
 693        $this->Mailer = 'sendmail';
 694    }
 695
 696    /**
 697     * Send messages using qmail.
 698     * @return void
 699     */
 700    public function isQmail()
 701    {
 702        $ini_sendmail_path = ini_get('sendmail_path');
 703        
 704        if (!stristr($ini_sendmail_path, 'qmail')) {
 705            $this->Sendmail = '/var/qmail/bin/qmail-inject';
 706        } else {
 707            $this->Sendmail = $ini_sendmail_path;
 708        }
 709        $this->Mailer = 'qmail';
 710    }
 711
 712    /**
 713     * Add a "To" address.
 714     * @param string $address
 715     * @param string $name
 716     * @return bool true on success, false if address already used
 717     */
 718    public function addAddress($address, $name = '')
 719    {
 720        return $this->addAnAddress('to', $address, $name);
 721    }
 722
 723    /**
 724     * Add a "CC" address.
 725     * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
 726     * @param string $address
 727     * @param string $name
 728     * @return bool true on success, false if address already used
 729     */
 730    public function addCC($address, $name = '')
 731    {
 732        return $this->addAnAddress('cc', $address, $name);
 733    }
 734
 735    /**
 736     * Add a "BCC" address.
 737     * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
 738     * @param string $address
 739     * @param string $name
 740     * @return bool true on success, false if address already used
 741     */
 742    public function addBCC($address, $name = '')
 743    {
 744        return $this->addAnAddress('bcc', $address, $name);
 745    }
 746
 747    /**
 748     * Add a "Reply-to" address.
 749     * @param string $address
 750     * @param string $name
 751     * @return bool
 752     */
 753    public function addReplyTo($address, $name = '')
 754    {
 755        return $this->addAnAddress('Reply-To', $address, $name);
 756    }
 757
 758    /**
 759     * Add an address to one of the recipient arrays.
 760     * Addresses that have been added already return false, but do not throw exceptions
 761     * @param string $kind One of 'to', 'cc', 'bcc', 'ReplyTo'
 762     * @param string $address The email address to send to
 763     * @param string $name
 764     * @throws phpmailerException
 765     * @return bool true on success, false if address already used or invalid in some way
 766     * @access protected
 767     */
 768    protected function addAnAddress($kind, $address, $name = '')
 769    {
 770        if (!preg_match('/^(to|cc|bcc|Reply-To)$/', $kind)) {
 771            $this->setError($this->lang('Invalid recipient array') . ': ' . $kind);
 772            $this->edebug($this->lang('Invalid recipient array') . ': ' . $kind);
 773            if ($this->exceptions) {
 774                throw new phpmailerException('Invalid recipient array: ' . $kind);
 775            }
 776            return false;
 777        }
 778        $address = trim($address);
 779        $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
 780        if (!$this->validateAddress($address)) {
 781            $this->setError($this->lang('invalid_address') . ': ' . $address);
 782            $this->edebug($this->lang('invalid_address') . ': ' . $address);
 783            if ($this->exceptions) {
 784                throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
 785            }
 786            return false;
 787        }
 788        if ($kind != 'Reply-To') {
 789            if (!isset($this->all_recipients[strtolower($address)])) {
 790                array_push($this->$kind, array($address, $name));
 791                $this->all_recipients[strtolower($address)] = true;
 792                return true;
 793            }
 794        } else {
 795            if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
 796                $this->ReplyTo[strtolower($address)] = array($address, $name);
 797                return true;
 798            }
 799        }
 800        return false;
 801    }
 802
 803    /**
 804     * Set the From and FromName properties.
 805     * @param string $address
 806     * @param string $name
 807     * @param bool $auto Whether to also set the Sender address, defaults to true
 808     * @throws phpmailerException
 809     * @return bool
 810     */
 811    public function setFrom($address, $name = '', $auto = true)
 812    {
 813        $address = trim($address);
 814        $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
 815        if (!$this->validateAddress($address)) {
 816            $this->setError($this->lang('invalid_address') . ': ' . $address);
 817            $this->edebug($this->lang('invalid_address') . ': ' . $address);
 818            if ($this->exceptions) {
 819                throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
 820            }
 821            return false;
 822        }
 823        $this->From = $address;
 824        $this->FromName = $name;
 825        if ($auto) {
 826            if (empty($this->Sender)) {
 827                $this->Sender = $address;
 828            }
 829        }
 830        return true;
 831    }
 832
 833    /**
 834     * Return the Message-ID header of the last email.
 835     * Technically this is the value from the last time the headers were created,
 836     * but it's also the message ID of the last sent message except in
 837     * pathological cases.
 838     * @return string
 839     */
 840    public function getLastMessageID()
 841    {
 842        return $this->lastMessageID;
 843    }
 844
 845    /**
 846     * Check that a string looks like an email address.
 847     * @param string $address The email address to check
 848     * @param string $patternselect A selector for the validation pattern to use :
 849     * * `auto` Pick strictest one automatically;
 850     * * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14;
 851     * * `pcre` Use old PCRE implementation;
 852     * * `php` Use PHP built-in FILTER_VALIDATE_EMAIL; same as pcre8 but does not allow 'dotless' domains;
 853     * * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements.
 854     * * `noregex` Don't use a regex: super fast, really dumb.
 855     * @return bool
 856     * @static
 857     * @access public
 858     */
 859    public static function validateAddress($address, $patternselect = 'auto')
 860    {
 861        if (!$patternselect or $patternselect == 'auto') {
 862            if (defined('PCRE_VERSION')) { //Check this constant so it works when extension_loaded() is disabled
 863                if (version_compare(PCRE_VERSION, '8.0') >= 0) {
 864                    $patternselect = 'pcre8';
 865                } else {
 866                    $patternselect = 'pcre';
 867                }
 868            } else {
 869                //Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
 870                if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
 871                    $patternselect = 'php';
 872                } else {
 873                    $patternselect = 'noregex';
 874                }
 875            }
 876        }
 877        switch ($patternselect) {
 878            case 'pcre8':
 879                /**
 880                 * Uses the same RFC5322 regex on which FILTER_VALIDATE_EMAIL is based, but allows dotless domains.
 881                 * @link http://squiloople.com/2009/12/20/email-address-validation/
 882                 * @copyright 2009-2010 Michael Rushton
 883                 * Feel free to use and redistribute this code. But please keep this copyright notice.
 884                 */
 885                return (bool)preg_match(
 886                    '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
 887                    '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
 888                    '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
 889                    '([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
 890                    '(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
 891                    '(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
 892                    '|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
 893                    '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
 894                    '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
 895                    $address
 896                );
 897                break;
 898            case 'pcre':
 899                //An older regex that doesn't need a recent PCRE
 900                return (bool)preg_match(
 901                    '/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' .
 902                    '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' .
 903                    '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' .
 904                    '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' .
 905                    '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' .
 906                    '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' .
 907                    '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' .
 908                    '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' .
 909                    '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
 910                    '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
 911                    $address
 912                );
 913                break;
 914            case 'html5':
 915                /**
 916                 * This is the pattern used in the HTML5 spec for validation of 'email' type form input elements.
 917                 * @link http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state-(type=email)
 918                 */
 919                return (bool)preg_match('/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' .
 920                    '[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD', $address);
 921                break;
 922            case 'php':
 923            default:
 924                return (bool)filter_var($address, FILTER_VALIDATE_EMAIL);
 925                break;
 926            case 'noregex':
 927                //No PCRE! Do something _very_ approximate!
 928                //Check the address is 3 chars or longer and contains an @ that's not the first or last char
 929                return (strlen($address) >= 3
 930                    and strpos($address, '@') >= 1
 931                    and strpos($address, '@') != strlen($address) - 1);
 932                break;
 933        }
 934    }
 935
 936    /**
 937     * Create a message and send it.
 938     * Uses the sending method specified by $Mailer.
 939     * @throws phpmailerException
 940     * @return bool false on error - See the ErrorInfo property for details of the error.
 941     */
 942    public function send()
 943    {
 944        try {
 945            if (!$this->preSend()) {
 946                return false;
 947            }
 948            return $this->postSend();
 949        } catch (phpmailerException $exc) {
 950            $this->mailHeader = '';
 951            $this->setError($exc->getMessage());
 952            if ($this->exceptions) {
 953                throw $exc;
 954            }
 955            return false;
 956        }
 957    }
 958
 959    /**
 960     * Prepare a message for sending.
 961     * @throws phpmailerException
 962     * @return bool
 963     */
 964    public function preSend()
 965    {
 966        try {
 967            $this->mailHeader = '';
 968            if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
 969                throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL);
 970            }
 971
 972            // Set whether the message is multipart/alternative
 973            if (!empty($this->AltBody)) {
 974                $this->ContentType = 'multipart/alternative';
 975            }
 976
 977            $this->error_count = 0; // reset errors
 978            $this->setMessageType();
 979            // Refuse to send an empty message unless we are specifically allowing it
 980            if (!$this->AllowEmpty and empty($this->Body)) {
 981                throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
 982            }
 983
 984            $this->MIMEHeader = $this->createHeader();
 985            $this->MIMEBody = $this->createBody();
 986
 987            // To capture the complete message when using mail(), create
 988            // an extra header list which createHeader() doesn't fold in
 989            if ($this->Mailer == 'mail') {
 990                if (count($this->to) > 0) {
 991                    $this->mailHeader .= $this->addrAppend('To', $this->to);
 992                } else {
 993                    $this->mailHeader .= $this->headerLine('To', 'undisclosed-recipients:;');
 994                }
 995                $this->mailHeader .= $this->headerLine(
 996                    'Subject',
 997                    $this->encodeHeader($this->secureHeader(trim($this->Subject)))
 998                );
 999            }
1000
1001            // Sign with DKIM if enabled
1002            if (!empty($this->DKIM_domain)
1003                && !empty($this->DKIM_private)
1004                && !empty($this->DKIM_selector)
1005                && !empty($this->DKIM_domain)
1006                && file_exists($this->DKIM_private)) {
1007                $header_dkim = $this->DKIM_Add(
1008                    $this->MIMEHeader . $this->mailHeader,
1009                    $this->encodeHeader($this->secureHeader($this->Subject)),
1010                    $this->MIMEBody
1011                );
1012                $this->MIMEHeader = rtrim($this->MIMEHeader, "\r\n ") . self::CRLF .
1013                    str_replace("\r\n", "\n", $header_dkim) . self::CRLF;
1014            }
1015            return true;
1016
1017        } catch (phpmailerException $exc) {
1018            $this->setError($exc->getMessage());
1019            if ($this->exceptions) {
1020                throw $exc;
1021            }
1022            return false;
1023        }
1024    }
1025
1026    /**
1027     * Actually send a message.
1028     * Send the email via the selected mechanism
1029     * @throws phpmailerException
1030     * @return bool
1031     */
1032    public function postSend()
1033    {
1034        try {
1035            // Choose the mailer and send through it
1036            switch ($this->Mailer) {
1037                case 'sendmail':
1038                case 'qmail':
1039                    return $this->sendmailSend($this->MIMEHeader, $this->MIMEBody);
1040                case 'smtp':
1041                    return $this->smtpSend($this->MIMEHeader, $this->MIMEBody);
1042                case 'mail':
1043                    return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
1044                default:
1045                    $sendMethod = $this->Mailer.'Send';
1046                    if (method_exists($this, $sendMethod)) {
1047                        return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody);
1048                    }
1049                    
1050                    return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
1051            }
1052        } catch (phpmailerException $exc) {
1053            $this->setError($exc->getMessage());
1054            $this->edebug($exc->getMessage());
1055            if ($this->exceptions) {
1056                throw $exc;
1057            }
1058        }
1059        return false;
1060    }
1061
1062    /**
1063     * Send mail using the $Sendmail program.
1064     * @param string $header The message headers
1065     * @param string $body The message body
1066     * @see PHPMailer::$Sendmail
1067     * @throws phpmailerException
1068     * @access protected
1069     * @return bool
1070     */
1071    protected function sendmailSend($header, $body)
1072    {
1073        if ($this->Sender != '') {
1074            if ($this->Mailer == 'qmail') {
1075                $sendmail = sprintf('%s -f%s', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
1076            } else {
1077                $sendmail = sprintf('%s -oi -f%s -t', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
1078            }
1079        } else {
1080            if ($this->Mailer == 'qmail') {
1081                $sendmail = sprintf('%s', escapeshellcmd($this->Sendmail));
1082            } else {
1083                $sendmail = sprintf('%s -oi -t', escapeshellcmd($this->Sendmail));
1084            }
1085        }
1086        if ($this->SingleTo === true) {
1087            foreach ($this->SingleToArray as $val) {
1088                if (!@$mail = popen($sendmail, 'w')) {
1089                    throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
1090                }
1091                fputs($mail, 'To: ' . $val . "\n");
1092                fputs($mail, $header);
1093                fputs($mail, $body);
1094                $result = pclose($mail);
1095                // implement call back function if it exists
1096                $isSent = ($result == 0) ? 1 : 0;
1097                $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
1098                if ($result != 0) {
1099                    throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
1100                }
1101            }
1102        } else {
1103            if (!@$mail = popen($sendmail, 'w')) {
1104                throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
1105            }
1106            fputs($mail, $header);
1107            fputs($mail, $body);
1108            $result = pclose($mail);
1109            // implement call back function if it exists
1110            $isSent = ($result == 0) ? 1 : 0;
1111            $this->doCallback($isSent, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
1112            if ($result != 0) {
1113                throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
1114            }
1115        }
1116        return true;
1117    }
1118
1119    /**
1120     * Send mail using the PHP mail() function.
1121     * @param string $header The message headers
1122     * @param string $body The message body
1123     * @link http://www.php.net/manual/en/book.mail.php
1124     * @throws phpmailerException
1125     * @access protected
1126     * @return bool
1127     */
1128    protected function mailSend($header, $body)
1129    {
1130        $toArr = array();
1131        foreach ($this->to as $toaddr) {
1132            $toArr[] = $this->addrFormat($toaddr);
1133        }
1134        $to = implode(', ', $toArr);
1135
1136        if (empty($this->Sender)) {
1137            $params = ' ';
1138        } else {
1139            $params = sprintf('-f%s', $this->Sender);
1140        }
1141        if ($this->Sender != '' and !ini_get('safe_mode')) {
1142            $old_from = ini_get('sendmail_from');
1143            ini_set('sendmail_from', $this->Sender);
1144        }
1145        $result = false;
1146        if ($this->SingleTo === true && count($toArr) > 1) {
1147            foreach ($toArr as $val) {
1148                $result = $this->mailPassthru($val, $this->Subject, $body, $header, $params);
1149                // implement call back function if it exists
1150                $isSent = ($result == 1) ? 1 : 0;
1151                $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
1152            }
1153        } else {
1154            $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
1155            // implement call back function if it exists
1156            $isSent = ($result == 1) ? 1 : 0;
1157            $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
1158        }
1159        if (isset($old_from)) {
1160            ini_set('sendmail_from', $old_from);
1161        }
1162        if (!$result) {
1163            throw new phpmailerException($this->lang('instantiate'), self::STOP_CRITICAL);
1164        }
1165        return true;
1166    }
1167
1168    /**
1169     * Get an instance to use for SMTP operations.
1170     * Override this function to load your own SMTP implementation
1171     * @return SMTP
1172     */
1173    public function getSMTPInstance()
1174    {
1175        if (!is_object($this->smtp)) {
1176            $this->smtp = new SMTP;
1177        }
1178        return $this->smtp;
1179    }
1180
1181    /**
1182     * Send mail via SMTP.
1183     * Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
1184     * Uses the PHPMailerSMTP class by default.
1185     * @see PHPMailer::getSMTPInstance() to use a different class.
1186     * @param string $header The message headers
1187     * @param string $body The message body
1188     * @throws phpmailerException
1189     * @uses SMTP
1190     * @access protected
1191     * @return bool
1192     */
1193    protected function smtpSend($header, $body)
1194    {
1195        $bad_rcpt = array();
1196
1197        if (!$this->smtpConnect()) {
1198            throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
1199        }
1200        $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
1201        if (!$this->smtp->mail($smtp_from)) {
1202            $this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
1203            throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
1204        }
1205
1206        // Attempt to send to all recipients
1207        foreach ($this->to as $to) {
1208            if (!$this->smtp->recipient($to[0])) {
1209                $bad_rcpt[] = $to[0];
1210                $isSent = 0;
1211            } else {
1212                $isSent = 1;
1213            }
1214            $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body, $this->From);
1215        }
1216        foreach ($this->cc as $cc) {
1217            if (!$this->smtp->recipient($cc[0])) {
1218                $bad_rcpt[] = $cc[0];
1219                $isSent = 0;
1220            } else {
1221                $isSent = 1;
1222            }
1223            $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body, $this->From);
1224        }
1225        foreach ($this->bcc as $bcc) {
1226            if (!$this->smtp->recipient($bcc[0])) {
1227                $bad_rcpt[] = $bcc[0];
1228                $isSent = 0;
1229            } else {
1230                $isSent = 1;
1231            }
1232            $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body, $this->From);
1233        }
1234
1235        //Only send the DATA command if we have viable recipients
1236        if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) {
1237            throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
1238        }
1239        if ($this->SMTPKeepAlive == true) {
1240            $this->smtp->reset();
1241        } else {
1242            $this->smtp->quit();
1243            $this->smtp->close();
1244        }
1245        if (count($bad_rcpt) > 0) { //Create error message for any bad addresses
1246            throw new phpmailerException(
1247                $this->lang('recipients_failed') . implode(', ', $bad_rcpt),
1248                self::STOP_CONTINUE
1249            );
1250        }
1251        return true;
1252    }
1253
1254    /**
1255     * Initiate a connection to an SMTP server.
1256     * Returns false if the operation failed.
1257     * @param array $options An array of options compatible with stream_context_create()
1258     * @uses SMTP
1259     * @access public
1260     * @throws phpmailerException
1261     * @return bool
1262     */
1263    public function smtpConnect($options = array())
1264    {
1265        if (is_null($this->smtp)) {
1266            $this->smtp = $this->getSMTPInstance();
1267        }
1268
1269        //Already connected?
1270        if ($this->smtp->connected()) {
1271            return true;
1272        }
1273
1274        $this->smtp->setTimeout($this->Timeout);
1275        $this->smtp->setDebugLevel($this->SMTPDebug);
1276        $this->smtp->setDebugOutput($this->Debugoutput);
1277        $this->smtp->setVerp($this->do_verp);
1278        $hosts = explode(';', $this->Host);
1279        $lastexception = null;
1280
1281        foreach ($hosts as $hostentry) {
1282            $hostinfo = array();
1283            if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
1284                //Not a valid host entry
1285                continue;
1286            }
1287            //$hostinfo[2]: optional ssl or tls prefix
1288            //$hostinfo[3]: the hostname
1289            //$hostinfo[4]: optional port number
1290            //The host string prefix can temporarily override the current setting for SMTPSecure
1291            //If it's not specified, the default value is used
1292            $prefix = '';
1293            $tls = ($this->SMTPSecure == 'tls');
1294            if ($hostinfo[2] == 'ssl' or ($hostinfo[2] == '' and $this->SMTPSecure == 'ssl')) {
1295                $prefix = 'ssl://';
1296                $tls = false; //Can't have SSL and TLS at once
1297            } elseif ($hostinfo[2] == 'tls') {
1298                $tls = true;
1299                //tls doesn't use a prefix
1300            }
1301            $host = $hostinfo[3];
1302            $port = $this->Port;
1303            $tport = (integer)$hostinfo[4];
1304            if ($tport > 0 and $tport < 65536) {
1305                $port = $tport;
1306            }
1307            if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
1308                try {
1309                    if ($this->Helo) {
1310                        $hello = $this->Helo;
1311                    } else {
1312                        $hello = $this->serverHostname();
1313                    }
1314                    $this->smtp->hello($hello);
1315
1316                    if ($tls) {
1317                        if (!$this->smtp->startTLS()) {
1318                            throw new phpmailerException($this->lang('connect_host'));
1319                        }
1320                        //We must resend HELO after tls negotiation
1321                        $this->smtp->hello($hello);
1322                    }
1323                    if ($this->SMTPAuth) {
1324                        if (!$this->smtp->authenticate(
1325                            $this->Username,
1326                            $this->Password,
1327                            $this->AuthType,
1328                            $this->Realm,
1329                            $this->Workstation
1330                        )
1331                        ) {
1332                            throw new phpmailerException($this->lang('authenticate'));
1333                        }
1334                    }
1335                    return true;
1336                } catch (phpmailerException $exc) {
1337                    $lastexception = $exc;
1338                    //We must have connected, but then failed TLS or Auth, so close connection nicely
1339                    $this->smtp->quit();
1340                }
1341            }
1342        }
1343        //If we get here, all connection attempts have failed, so close connection hard
1344        $this->smtp->close();
1345        //As we've caught all exceptions, just report whatever the last one was
1346        if ($this->exceptions and !is_null($lastexception)) {
1347            throw $lastexception;
1348        }
1349        return false;
1350    }
1351
1352    /**
1353     * Close the active SMTP session if one exists.
1354     * @return void
1355     */
1356    public function smtpClose()
1357    {
1358        if ($this->smtp !== null) {
1359            if ($this->smtp->connected()) {
1360                $this->smtp->quit();
1361                $this->smtp->close();
1362            }
1363        }
1364    }
1365
1366    /**
1367     * Set the language for error messages.
1368     * Returns false if it cannot load the language file.
1369     * The default language is English.
1370     * @param string $langcode ISO 639-1 2-character language code (e.g. French is "fr")
1371     * @param string $lang_path Path to the language file directory, with trailing separator (slash)
1372     * @return bool
1373     * @access public
1374     */
1375    public function setLanguage($langcode = 'en', $lang_path = '')
1376    {
1377        //Define full set of translatable strings in English
1378        $PHPMAILER_LANG = array(
1379            'authenticate' => 'SMTP Error: Could not authenticate.',
1380            'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
1381            'data_not_accepted' => 'SMTP Error: data not accepted.',
1382            'empty_message' => 'Message body empty',
1383            'encoding' => 'Unknown encoding: ',
1384            'execute' => 'Could not execute: ',
1385            'file_access' => 'Could not access file: ',
1386            'file_open' => 'File Error: Could not open file: ',
1387            'from_failed' => 'The following From address failed: ',
1388            'instantiate' => 'Could not instantiate mail function.',
1389            'invalid_address' => 'Invalid address',
1390            'mailer_not_supported' => ' mailer is not supported.',
1391            'provide_address' => 'You must provide at least one recipient email address.',
1392            'recipients_failed' => 'SMTP Error: The following recipients failed: ',
1393            'signing' => 'Signing Error: ',
1394            'smtp_connect_failed' => 'SMTP connect() failed.',
1395            'smtp_error' => 'SMTP server error: ',
1396            'variable_set' => 'Cannot set or reset variable: '
1397        );
1398        if (empty($lang_path)) {
1399            //Calculate an absolute path so it can work if CWD is not here
1400            $lang_path = dirname(__FILE__). DIRECTORY_SEPARATOR . 'language'. DIRECTORY_SEPARATOR;
1401        }
1402        $foundlang = true;
1403        $lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php';
1404        if ($langcode != 'en') { //There is no English translation file
1405            //Make sure language file path is readable
1406            if (!is_readable($lang_file)) {
1407                $foundlang = false;
1408            } else {
1409                //Overwrite language-specific strings.
1410                //This way we'll never have missing translations.
1411                $foundlang = include $lang_file;
1412            }
1413        }
1414        $this->language = $PHPMAILER_LANG;
1415        return ($foundlang == true); //Returns false if language not found
1416    }
1417
1418    /**
1419     * Get the array of strings for the current language.
1420     * @return array
1421     */
1422    public function getTranslations()
1423    {
1424        return $this->language;
1425    }
1426
1427    /**
1428     * Create recipient headers.
1429     * @access public
1430     * @param string $type
1431     * @param array $addr An array of recipient,
1432     * where each recipient is a 2-element indexed array with element 0 containing an address
1433     * and element 1 containing a name, like:
1434     * array(array('joe@example.com', 'Joe User'), array('zoe@example.com', 'Zoe User'))
1435     * @return string
1436     */
1437    public function addrAppend($type, $addr)
1438    {
1439        $addresses = array();
1440        foreach ($addr as $address) {
1441            $addresses[] = $this->addrFormat($address);
1442        }
1443        return $type . ': ' . implode(', ', $addresses) . $this->LE;
1444    }
1445
1446    /**
1447     * Format an address for use in a message header.
1448     * @access public
1449     * @param array $addr A 2-element indexed array, element 0 containing an address, element 1 containing a name
1450     *      like array('joe@example.com', 'Joe User')
1451     * @return string
1452     */
1453    public function addrFormat($addr)
1454    {
1455        if (empty($addr[1])) { // No name provided
1456            return $this->secureHeader($addr[0]);
1457        } else {
1458            return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . ' <' . $this->secureHeader(
1459                $addr[0]
1460            ) . '>';
1461        }
1462    }
1463
1464    /**
1465     * Word-wrap message.
1466     * For use with mailers that do not automatically perform wrapping
1467     * and for quoted-printable encoded messages.
1468     * Original written by philippe.
1469     * @param string $message The message to wrap
1470     * @param integer $length The line length to wrap to
1471     * @param bool $qp_mode Whether to run in Quoted-Printable mode
1472     * @access public
1473     * @return string
1474     */
1475    public function wrapText($message, $length, $qp_mode = false)
1476    {
1477        $soft_break = ($qp_mode) ? sprintf(' =%s', $this->LE) : $this->LE;
1478        // If utf-8 encoding is used, we will need to make sure we don't
1479        // split multibyte characters when we wrap
1480        $is_utf8 = (strtolower($this->CharSet) == 'utf-8');
1481        $lelen = strlen($this->LE);
1482        $crlflen = strlen(self::CRLF);
1483
1484        $message = $this->fixEOL($message);
1485        if (substr($message, -$lelen) == $this->LE) {
1486            $message = substr($message, 0, -$lelen);
1487        }
1488
1489        $line = explode($this->LE, $message); // Magic. We know fixEOL uses $LE
1490        $message = '';
1491        for ($i = 0; $i < count($line); $i++) {
1492            $line_part = explode(' ', $line[$i]);
1493            $buf = '';
1494            for ($e = 0; $e < count($line_part); $e++) {
1495                $word = $line_part[$e];
1496                if ($qp_mode and (strlen($word) > $length)) {
1497                    $space_left = $length - strlen($buf) - $crlflen;
1498                    if ($e != 0) {
1499                        if ($space_left > 20) {
1500                            $len = $space_left;
1501                            if ($is_utf8) {
1502                                $len = $this->utf8CharBoundary($word, $len);
1503                            } elseif (substr($word, $len - 1, 1) == '=') {
1504                                $len--;
1505                            } elseif (substr($word, $len - 2, 1) == '=') {
1506                                $len -= 2;
1507                            }
1508                            $part = substr($word, 0, $len);
1509          

Large files files are truncated, but you can click here to view the full file