PageRenderTime 69ms CodeModel.GetById 6ms app.highlight 49ms RepoModel.GetById 1ms app.codeStats 1ms

/lib/phpmailer/class.phpmailer.php

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

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