PageRenderTime 52ms CodeModel.GetById 5ms app.highlight 33ms RepoModel.GetById 1ms app.codeStats 1ms

/PHPMailer/class.phpmailer.php

https://github.com/bobaz/formularioPHP
PHP | 3414 lines | 2001 code | 230 blank | 1183 comment | 342 complexity | f922ed6177949a00d180489bc9da21ec 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.8';
  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 = 'usuario@correo.com';
 260
 261    /**
 262     * SMTP password.
 263     * @type string
 264     */
 265    public $Password = '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        $this->exceptions = ($exceptions == true);
 571        //Make sure our autoloader is loaded
 572        if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
 573            $autoload = spl_autoload_functions();
 574            if ($autoload === false or !in_array('PHPMailerAutoload', $autoload)) {
 575                require 'PHPMailerAutoload.php';
 576            }
 577        }
 578    }
 579
 580    /**
 581     * Destructor.
 582     */
 583    public function __destruct()
 584    {
 585        if ($this->Mailer == 'smtp') { //close any open SMTP connection nicely
 586            $this->smtpClose();
 587        }
 588    }
 589
 590    /**
 591     * Call mail() in a safe_mode-aware fashion.
 592     * Also, unless sendmail_path points to sendmail (or something that
 593     * claims to be sendmail), don't pass params (not a perfect fix,
 594     * but it will do)
 595     * @param string $to To
 596     * @param string $subject Subject
 597     * @param string $body Message Body
 598     * @param string $header Additional Header(s)
 599     * @param string $params Params
 600     * @access private
 601     * @return bool
 602     */
 603    private function mailPassthru($to, $subject, $body, $header, $params)
 604    {
 605        //Check overloading of mail function to avoid double-encoding
 606        if (ini_get('mbstring.func_overload') & 1) {
 607            $subject = $this->secureHeader($subject);
 608        } else {
 609            $subject = $this->encodeHeader($this->secureHeader($subject));
 610        }
 611        if (ini_get('safe_mode') || !($this->UseSendmailOptions)) {
 612            $result = @mail($to, $subject, $body, $header);
 613        } else {
 614            $result = @mail($to, $subject, $body, $header, $params);
 615        }
 616        return $result;
 617    }
 618
 619    /**
 620     * Output debugging info via user-defined method.
 621     * Only if debug output is enabled.
 622     * @see PHPMailer::$Debugoutput
 623     * @see PHPMailer::$SMTPDebug
 624     * @param string $str
 625     */
 626    protected function edebug($str)
 627    {
 628        if (!$this->SMTPDebug) {
 629            return;
 630        }
 631        switch ($this->Debugoutput) {
 632            case 'error_log':
 633                error_log($str);
 634                break;
 635            case 'html':
 636                //Cleans up output a bit for a better looking display that's HTML-safe
 637                echo htmlentities(preg_replace('/[\r\n]+/', '', $str), ENT_QUOTES, $this->CharSet) . "<br>\n";
 638                break;
 639            case 'echo':
 640            default:
 641                echo $str."\n";
 642        }
 643    }
 644
 645    /**
 646     * Sets message type to HTML or plain.
 647     * @param bool $isHtml True for HTML mode.
 648     * @return void
 649     */
 650    public function isHTML($isHtml = true)
 651    {
 652        if ($isHtml) {
 653            $this->ContentType = 'text/html';
 654        } else {
 655            $this->ContentType = 'text/plain';
 656        }
 657    }
 658
 659    /**
 660     * Send messages using SMTP.
 661     * @return void
 662     */
 663    public function isSMTP()
 664    {
 665        $this->Mailer = 'smtp';
 666    }
 667
 668    /**
 669     * Send messages using PHP's mail() function.
 670     * @return void
 671     */
 672    public function isMail()
 673    {
 674        $this->Mailer = 'mail';
 675    }
 676
 677    /**
 678     * Send messages using $Sendmail.
 679     * @return void
 680     */
 681    public function isSendmail()
 682    {
 683        $ini_sendmail_path = ini_get('sendmail_path');
 684
 685        if (!stristr($ini_sendmail_path, 'sendmail')) {
 686            $this->Sendmail = '/usr/sbin/sendmail';
 687        } else {
 688            $this->Sendmail = $ini_sendmail_path;
 689        }
 690        $this->Mailer = 'sendmail';
 691    }
 692
 693    /**
 694     * Send messages using qmail.
 695     * @return void
 696     */
 697    public function isQmail()
 698    {
 699        $ini_sendmail_path = ini_get('sendmail_path');
 700
 701        if (!stristr($ini_sendmail_path, 'qmail')) {
 702            $this->Sendmail = '/var/qmail/bin/qmail-inject';
 703        } else {
 704            $this->Sendmail = $ini_sendmail_path;
 705        }
 706        $this->Mailer = 'qmail';
 707    }
 708
 709    /**
 710     * Add a "To" address.
 711     * @param string $address
 712     * @param string $name
 713     * @return bool true on success, false if address already used
 714     */
 715    public function addAddress($address, $name = '')
 716    {
 717        return $this->addAnAddress('to', $address, $name);
 718    }
 719
 720    /**
 721     * Add a "CC" address.
 722     * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
 723     * @param string $address
 724     * @param string $name
 725     * @return bool true on success, false if address already used
 726     */
 727    public function addCC($address, $name = '')
 728    {
 729        return $this->addAnAddress('cc', $address, $name);
 730    }
 731
 732    /**
 733     * Add a "BCC" address.
 734     * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
 735     * @param string $address
 736     * @param string $name
 737     * @return bool true on success, false if address already used
 738     */
 739    public function addBCC($address, $name = '')
 740    {
 741        return $this->addAnAddress('bcc', $address, $name);
 742    }
 743
 744    /**
 745     * Add a "Reply-to" address.
 746     * @param string $address
 747     * @param string $name
 748     * @return bool
 749     */
 750    public function addReplyTo($address, $name = '')
 751    {
 752        return $this->addAnAddress('Reply-To', $address, $name);
 753    }
 754
 755    /**
 756     * Add an address to one of the recipient arrays.
 757     * Addresses that have been added already return false, but do not throw exceptions
 758     * @param string $kind One of 'to', 'cc', 'bcc', 'ReplyTo'
 759     * @param string $address The email address to send to
 760     * @param string $name
 761     * @throws phpmailerException
 762     * @return bool true on success, false if address already used or invalid in some way
 763     * @access protected
 764     */
 765    protected function addAnAddress($kind, $address, $name = '')
 766    {
 767        if (!preg_match('/^(to|cc|bcc|Reply-To)$/', $kind)) {
 768            $this->setError($this->lang('Invalid recipient array') . ': ' . $kind);
 769            $this->edebug($this->lang('Invalid recipient array') . ': ' . $kind);
 770            if ($this->exceptions) {
 771                throw new phpmailerException('Invalid recipient array: ' . $kind);
 772            }
 773            return false;
 774        }
 775        $address = trim($address);
 776        $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
 777        if (!$this->validateAddress($address)) {
 778            $this->setError($this->lang('invalid_address') . ': ' . $address);
 779            $this->edebug($this->lang('invalid_address') . ': ' . $address);
 780            if ($this->exceptions) {
 781                throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
 782            }
 783            return false;
 784        }
 785        if ($kind != 'Reply-To') {
 786            if (!isset($this->all_recipients[strtolower($address)])) {
 787                array_push($this->$kind, array($address, $name));
 788                $this->all_recipients[strtolower($address)] = true;
 789                return true;
 790            }
 791        } else {
 792            if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
 793                $this->ReplyTo[strtolower($address)] = array($address, $name);
 794                return true;
 795            }
 796        }
 797        return false;
 798    }
 799
 800    /**
 801     * Set the From and FromName properties.
 802     * @param string $address
 803     * @param string $name
 804     * @param bool $auto Whether to also set the Sender address, defaults to true
 805     * @throws phpmailerException
 806     * @return bool
 807     */
 808    public function setFrom($address, $name = '', $auto = true)
 809    {
 810        $address = trim($address);
 811        $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
 812        if (!$this->validateAddress($address)) {
 813            $this->setError($this->lang('invalid_address') . ': ' . $address);
 814            $this->edebug($this->lang('invalid_address') . ': ' . $address);
 815            if ($this->exceptions) {
 816                throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
 817            }
 818            return false;
 819        }
 820        $this->From = $address;
 821        $this->FromName = $name;
 822        if ($auto) {
 823            if (empty($this->Sender)) {
 824                $this->Sender = $address;
 825            }
 826        }
 827        return true;
 828    }
 829
 830    /**
 831     * Return the Message-ID header of the last email.
 832     * Technically this is the value from the last time the headers were created,
 833     * but it's also the message ID of the last sent message except in
 834     * pathological cases.
 835     * @return string
 836     */
 837    public function getLastMessageID()
 838    {
 839        return $this->lastMessageID;
 840    }
 841
 842    /**
 843     * Check that a string looks like an email address.
 844     * @param string $address The email address to check
 845     * @param string $patternselect A selector for the validation pattern to use :
 846     * * `auto` Pick strictest one automatically;
 847     * * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14;
 848     * * `pcre` Use old PCRE implementation;
 849     * * `php` Use PHP built-in FILTER_VALIDATE_EMAIL; same as pcre8 but does not allow 'dotless' domains;
 850     * * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements.
 851     * * `noregex` Don't use a regex: super fast, really dumb.
 852     * @return bool
 853     * @static
 854     * @access public
 855     */
 856    public static function validateAddress($address, $patternselect = 'auto')
 857    {
 858        if (!$patternselect or $patternselect == 'auto') {
 859            if (defined('PCRE_VERSION')) { //Check this constant so it works when extension_loaded() is disabled
 860                if (version_compare(PCRE_VERSION, '8.0') >= 0) {
 861                    $patternselect = 'pcre8';
 862                } else {
 863                    $patternselect = 'pcre';
 864                }
 865            } else {
 866                //Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
 867                if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
 868                    $patternselect = 'php';
 869                } else {
 870                    $patternselect = 'noregex';
 871                }
 872            }
 873        }
 874        switch ($patternselect) {
 875            case 'pcre8':
 876                /**
 877                 * Uses the same RFC5322 regex on which FILTER_VALIDATE_EMAIL is based, but allows dotless domains.
 878                 * @link http://squiloople.com/2009/12/20/email-address-validation/
 879                 * @copyright 2009-2010 Michael Rushton
 880                 * Feel free to use and redistribute this code. But please keep this copyright notice.
 881                 */
 882                return (bool)preg_match(
 883                    '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
 884                    '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
 885                    '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
 886                    '([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
 887                    '(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
 888                    '(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
 889                    '|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
 890                    '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
 891                    '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
 892                    $address
 893                );
 894            case 'pcre':
 895                //An older regex that doesn't need a recent PCRE
 896                return (bool)preg_match(
 897                    '/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' .
 898                    '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' .
 899                    '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' .
 900                    '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' .
 901                    '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' .
 902                    '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' .
 903                    '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' .
 904                    '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' .
 905                    '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
 906                    '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
 907                    $address
 908                );
 909            case 'html5':
 910                /**
 911                 * This is the pattern used in the HTML5 spec for validation of 'email' type form input elements.
 912                 * @link http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state-(type=email)
 913                 */
 914                return (bool)preg_match(
 915                    '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' .
 916                    '[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD',
 917                    $address
 918                );
 919            case 'noregex':
 920                //No PCRE! Do something _very_ approximate!
 921                //Check the address is 3 chars or longer and contains an @ that's not the first or last char
 922                return (strlen($address) >= 3
 923                    and strpos($address, '@') >= 1
 924                    and strpos($address, '@') != strlen($address) - 1);
 925            case 'php':
 926            default:
 927                return (bool)filter_var($address, FILTER_VALIDATE_EMAIL);
 928        }
 929    }
 930
 931    /**
 932     * Create a message and send it.
 933     * Uses the sending method specified by $Mailer.
 934     * @throws phpmailerException
 935     * @return bool false on error - See the ErrorInfo property for details of the error.
 936     */
 937    public function send()
 938    {
 939        try {
 940            if (!$this->preSend()) {
 941                return false;
 942            }
 943            return $this->postSend();
 944        } catch (phpmailerException $exc) {
 945            $this->mailHeader = '';
 946            $this->setError($exc->getMessage());
 947            if ($this->exceptions) {
 948                throw $exc;
 949            }
 950            return false;
 951        }
 952    }
 953
 954    /**
 955     * Prepare a message for sending.
 956     * @throws phpmailerException
 957     * @return bool
 958     */
 959    public function preSend()
 960    {
 961        try {
 962            $this->mailHeader = '';
 963            if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
 964                throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL);
 965            }
 966
 967            // Set whether the message is multipart/alternative
 968            if (!empty($this->AltBody)) {
 969                $this->ContentType = 'multipart/alternative';
 970            }
 971
 972            $this->error_count = 0; // reset errors
 973            $this->setMessageType();
 974            // Refuse to send an empty message unless we are specifically allowing it
 975            if (!$this->AllowEmpty and empty($this->Body)) {
 976                throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
 977            }
 978
 979            $this->MIMEHeader = $this->createHeader();
 980            $this->MIMEBody = $this->createBody();
 981
 982            // To capture the complete message when using mail(), create
 983            // an extra header list which createHeader() doesn't fold in
 984            if ($this->Mailer == 'mail') {
 985                if (count($this->to) > 0) {
 986                    $this->mailHeader .= $this->addrAppend('To', $this->to);
 987                } else {
 988                    $this->mailHeader .= $this->headerLine('To', 'undisclosed-recipients:;');
 989                }
 990                $this->mailHeader .= $this->headerLine(
 991                    'Subject',
 992                    $this->encodeHeader($this->secureHeader(trim($this->Subject)))
 993                );
 994            }
 995
 996            // Sign with DKIM if enabled
 997            if (!empty($this->DKIM_domain)
 998                && !empty($this->DKIM_private)
 999                && !empty($this->DKIM_selector)
1000                && !empty($this->DKIM_domain)
1001                && file_exists($this->DKIM_private)) {
1002                $header_dkim = $this->DKIM_Add(
1003                    $this->MIMEHeader . $this->mailHeader,
1004                    $this->encodeHeader($this->secureHeader($this->Subject)),
1005                    $this->MIMEBody
1006                );
1007                $this->MIMEHeader = rtrim($this->MIMEHeader, "\r\n ") . self::CRLF .
1008                    str_replace("\r\n", "\n", $header_dkim) . self::CRLF;
1009            }
1010            return true;
1011
1012        } catch (phpmailerException $exc) {
1013            $this->setError($exc->getMessage());
1014            if ($this->exceptions) {
1015                throw $exc;
1016            }
1017            return false;
1018        }
1019    }
1020
1021    /**
1022     * Actually send a message.
1023     * Send the email via the selected mechanism
1024     * @throws phpmailerException
1025     * @return bool
1026     */
1027    public function postSend()
1028    {
1029        try {
1030            // Choose the mailer and send through it
1031            switch ($this->Mailer) {
1032                case 'sendmail':
1033                case 'qmail':
1034                    return $this->sendmailSend($this->MIMEHeader, $this->MIMEBody);
1035                case 'smtp':
1036                    return $this->smtpSend($this->MIMEHeader, $this->MIMEBody);
1037                case 'mail':
1038                    return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
1039                default:
1040                    $sendMethod = $this->Mailer.'Send';
1041                    if (method_exists($this, $sendMethod)) {
1042                        return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody);
1043                    }
1044
1045                    return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
1046            }
1047        } catch (phpmailerException $exc) {
1048            $this->setError($exc->getMessage());
1049            $this->edebug($exc->getMessage());
1050            if ($this->exceptions) {
1051                throw $exc;
1052            }
1053        }
1054        return false;
1055    }
1056
1057    /**
1058     * Send mail using the $Sendmail program.
1059     * @param string $header The message headers
1060     * @param string $body The message body
1061     * @see PHPMailer::$Sendmail
1062     * @throws phpmailerException
1063     * @access protected
1064     * @return bool
1065     */
1066    protected function sendmailSend($header, $body)
1067    {
1068        if ($this->Sender != '') {
1069            if ($this->Mailer == 'qmail') {
1070                $sendmail = sprintf('%s -f%s', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
1071            } else {
1072                $sendmail = sprintf('%s -oi -f%s -t', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
1073            }
1074        } else {
1075            if ($this->Mailer == 'qmail') {
1076                $sendmail = sprintf('%s', escapeshellcmd($this->Sendmail));
1077            } else {
1078                $sendmail = sprintf('%s -oi -t', escapeshellcmd($this->Sendmail));
1079            }
1080        }
1081        if ($this->SingleTo === true) {
1082            foreach ($this->SingleToArray as $toAddr) {
1083                if (!@$mail = popen($sendmail, 'w')) {
1084                    throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
1085                }
1086                fputs($mail, 'To: ' . $toAddr . "\n");
1087                fputs($mail, $header);
1088                fputs($mail, $body);
1089                $result = pclose($mail);
1090                $this->doCallback(
1091                    ($result == 0),
1092                    array($toAddr),
1093                    $this->cc,
1094                    $this->bcc,
1095                    $this->Subject,
1096                    $body,
1097                    $this->From
1098                );
1099                if ($result != 0) {
1100                    throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
1101                }
1102            }
1103        } else {
1104            if (!@$mail = popen($sendmail, 'w')) {
1105                throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
1106            }
1107            fputs($mail, $header);
1108            fputs($mail, $body);
1109            $result = pclose($mail);
1110            $this->doCallback(($result == 0), $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
1111            if ($result != 0) {
1112                throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
1113            }
1114        }
1115        return true;
1116    }
1117
1118    /**
1119     * Send mail using the PHP mail() function.
1120     * @param string $header The message headers
1121     * @param string $body The message body
1122     * @link http://www.php.net/manual/en/book.mail.php
1123     * @throws phpmailerException
1124     * @access protected
1125     * @return bool
1126     */
1127    protected function mailSend($header, $body)
1128    {
1129        $toArr = array();
1130        foreach ($this->to as $toaddr) {
1131            $toArr[] = $this->addrFormat($toaddr);
1132        }
1133        $to = implode(', ', $toArr);
1134
1135        if (empty($this->Sender)) {
1136            $params = ' ';
1137        } else {
1138            $params = sprintf('-f%s', $this->Sender);
1139        }
1140        if ($this->Sender != '' and !ini_get('safe_mode')) {
1141            $old_from = ini_get('sendmail_from');
1142            ini_set('sendmail_from', $this->Sender);
1143        }
1144        $result = false;
1145        if ($this->SingleTo === true && count($toArr) > 1) {
1146            foreach ($toArr as $toAddr) {
1147                $result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
1148                $this->doCallback($result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
1149            }
1150        } else {
1151            $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
1152            $this->doCallback($result, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
1153        }
1154        if (isset($old_from)) {
1155            ini_set('sendmail_from', $old_from);
1156        }
1157        if (!$result) {
1158            throw new phpmailerException($this->lang('instantiate'), self::STOP_CRITICAL);
1159        }
1160        return true;
1161    }
1162
1163    /**
1164     * Get an instance to use for SMTP operations.
1165     * Override this function to load your own SMTP implementation
1166     * @return SMTP
1167     */
1168    public function getSMTPInstance()
1169    {
1170        if (!is_object($this->smtp)) {
1171            $this->smtp = new SMTP;
1172        }
1173        return $this->smtp;
1174    }
1175
1176    /**
1177     * Send mail via SMTP.
1178     * Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
1179     * Uses the PHPMailerSMTP class by default.
1180     * @see PHPMailer::getSMTPInstance() to use a different class.
1181     * @param string $header The message headers
1182     * @param string $body The message body
1183     * @throws phpmailerException
1184     * @uses SMTP
1185     * @access protected
1186     * @return bool
1187     */
1188    protected function smtpSend($header, $body)
1189    {
1190        $bad_rcpt = array();
1191
1192        if (!$this->smtpConnect()) {
1193            throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
1194        }
1195        $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
1196        if (!$this->smtp->mail($smtp_from)) {
1197            $this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
1198            throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
1199        }
1200
1201        // Attempt to send to all recipients
1202        foreach ($this->to as $to) {
1203            if (!$this->smtp->recipient($to[0])) {
1204                $bad_rcpt[] = $to[0];
1205                $isSent = false;
1206            } else {
1207                $isSent = true;
1208            }
1209            $this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From);
1210        }
1211        foreach ($this->cc as $cc) {
1212            if (!$this->smtp->recipient($cc[0])) {
1213                $bad_rcpt[] = $cc[0];
1214                $isSent = false;
1215            } else {
1216                $isSent = true;
1217            }
1218            $this->doCallback($isSent, array(), array($cc[0]), array(), $this->Subject, $body, $this->From);
1219        }
1220        foreach ($this->bcc as $bcc) {
1221            if (!$this->smtp->recipient($bcc[0])) {
1222                $bad_rcpt[] = $bcc[0];
1223                $isSent = false;
1224            } else {
1225                $isSent = true;
1226            }
1227            $this->doCallback($isSent, array(), array(), array($bcc[0]), $this->Subject, $body, $this->From);
1228        }
1229
1230        // Only send the DATA command if we have viable recipients
1231        if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) {
1232            throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
1233        }
1234        if ($this->SMTPKeepAlive == true) {
1235            $this->smtp->reset();
1236        } else {
1237            $this->smtp->quit();
1238            $this->smtp->close();
1239        }
1240        if (count($bad_rcpt) > 0) { // Create error message for any bad addresses
1241            throw new phpmailerException(
1242                $this->lang('recipients_failed') . implode(', ', $bad_rcpt),
1243                self::STOP_CONTINUE
1244            );
1245        }
1246        return true;
1247    }
1248
1249    /**
1250     * Initiate a connection to an SMTP server.
1251     * Returns false if the operation failed.
1252     * @param array $options An array of options compatible with stream_context_create()
1253     * @uses SMTP
1254     * @access public
1255     * @throws phpmailerException
1256     * @return bool
1257     */
1258    public function smtpConnect($options = array())
1259    {
1260        if (is_null($this->smtp)) {
1261            $this->smtp = $this->getSMTPInstance();
1262        }
1263
1264        // Already connected?
1265        if ($this->smtp->connected()) {
1266            return true;
1267        }
1268
1269        $this->smtp->setTimeout($this->Timeout);
1270        $this->smtp->setDebugLevel($this->SMTPDebug);
1271        $this->smtp->setDebugOutput($this->Debugoutput);
1272        $this->smtp->setVerp($this->do_verp);
1273        $hosts = explode(';', $this->Host);
1274        $lastexception = null;
1275
1276        foreach ($hosts as $hostentry) {
1277            $hostinfo = array();
1278            if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
1279                // Not a valid host entry
1280                continue;
1281            }
1282            // $hostinfo[2]: optional ssl or tls prefix
1283            // $hostinfo[3]: the hostname
1284            // $hostinfo[4]: optional port number
1285            // The host string prefix can temporarily override the current setting for SMTPSecure
1286            // If it's not specified, the default value is used
1287            $prefix = '';
1288            $tls = ($this->SMTPSecure == 'tls');
1289            if ($hostinfo[2] == 'ssl' or ($hostinfo[2] == '' and $this->SMTPSecure == 'ssl')) {
1290                $prefix = 'ssl://';
1291                $tls = false; // Can't have SSL and TLS at once
1292            } elseif ($hostinfo[2] == 'tls') {
1293                $tls = true;
1294                // tls doesn't use a prefix
1295            }
1296            $host = $hostinfo[3];
1297            $port = $this->Port;
1298            $tport = (integer)$hostinfo[4];
1299            if ($tport > 0 and $tport < 65536) {
1300                $port = $tport;
1301            }
1302            if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
1303                try {
1304                    if ($this->Helo) {
1305                        $hello = $this->Helo;
1306                    } else {
1307                        $hello = $this->serverHostname();
1308                    }
1309                    $this->smtp->hello($hello);
1310
1311                    if ($tls) {
1312                        if (!$this->smtp->startTLS()) {
1313                            throw new phpmailerException($this->lang('connect_host'));
1314                        }
1315                        // We must resend HELO after tls negotiation
1316                        $this->smtp->hello($hello);
1317                    }
1318                    if ($this->SMTPAuth) {
1319                        if (!$this->smtp->authenticate(
1320                            $this->Username,
1321                            $this->Password,
1322                            $this->AuthType,
1323                            $this->Realm,
1324                            $this->Workstation
1325                        )
1326                        ) {
1327                            throw new phpmailerException($this->lang('authenticate'));
1328                        }
1329                    }
1330                    return true;
1331                } catch (phpmailerException $exc) {
1332                    $lastexception = $exc;
1333                    // We must have connected, but then failed TLS or Auth, so close connection nicely
1334                    $this->smtp->quit();
1335                }
1336            }
1337        }
1338        // If we get here, all connection attempts have failed, so close connection hard
1339        $this->smtp->close();
1340        // As we've caught all exceptions, just report whatever the last one was
1341        if ($this->exceptions and !is_null($lastexception)) {
1342            throw $lastexception;
1343        }
1344        return false;
1345    }
1346
1347    /**
1348     * Close the active SMTP session if one exists.
1349     * @return void
1350     */
1351    public function smtpClose()
1352    {
1353        if ($this->smtp !== null) {
1354            if ($this->smtp->connected()) {
1355                $this->smtp->quit();
1356                $this->smtp->close();
1357            }
1358        }
1359    }
1360
1361    /**
1362     * Set the language for error messages.
1363     * Returns false if it cannot load the language file.
1364     * The default language is English.
1365     * @param string $langcode ISO 639-1 2-character language code (e.g. French is "fr")
1366     * @param string $lang_path Path to the language file directory, with trailing separator (slash)
1367     * @return bool
1368     * @access public
1369     */
1370    public function setLanguage($langcode = 'en', $lang_path = '')
1371    {
1372        // Define full set of translatable strings in English
1373        $PHPMAILER_LANG = array(
1374            'authenticate' => 'SMTP Error: Could not authenticate.',
1375            'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
1376            'data_not_accepted' => 'SMTP Error: data not accepted.',
1377            'empty_message' => 'Message body empty',
1378            'encoding' => 'Unknown encoding: ',
1379            'execute' => 'Could not execute: ',
1380            'file_access' => 'Could not access file: ',
1381            'file_open' => 'File Error: Could not open file: ',
1382            'from_failed' => 'The following From address failed: ',
1383            'instantiate' => 'Could not instantiate mail function.',
1384            'invalid_address' => 'Invalid address',
1385            'mailer_not_supported' => ' mailer is not supported.',
1386            'provide_address' => 'You must provide at least one recipient email address.',
1387            'recipients_failed' => 'SMTP Error: The following recipients failed: ',
1388            'signing' => 'Signing Error: ',
1389            'smtp_connect_failed' => 'SMTP connect() failed.',
1390            'smtp_error' => 'SMTP server error: ',
1391            'variable_set' => 'Cannot set or reset variable: '
1392        );
1393        if (empty($lang_path)) {
1394            // Calculate an absolute path so it can work if CWD is not here
1395            $lang_path = dirname(__FILE__). DIRECTORY_SEPARATOR . 'language'. DIRECTORY_SEPARATOR;
1396        }
1397        $foundlang = true;
1398        $lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php';
1399        if ($langcode != 'en') { // There is no English translation file
1400            // Make sure language file path is readable
1401            if (!is_readable($lang_file)) {
1402                $foundlang = false;
1403            } else {
1404                // Overwrite language-specific strings.
1405                // This way we'll never have missing translations.
1406                $foundlang = include $lang_file;
1407            }
1408        }
1409        $this->language = $PHPMAILER_LANG;
1410        return ($foundlang == true); // Returns false if language not found
1411    }
1412
1413    /**
1414     * Get the array of strings for the current language.
1415     * @return array
1416     */
1417    public function getTranslations()
1418    {
1419        return $this->language;
1420    }
1421
1422    /**
1423     * Create recipient headers.
1424     * @access public
1425     * @param string $type
1426     * @param array $addr An array of recipient,
1427     * where each recipient is a 2-element indexed array with element 0 containing an address
1428     * and element 1 containing a name, like:
1429     * array(array('joe@example.com', 'Joe User'), array('zoe@example.com', 'Zoe User'))
1430     * @return string
1431     */
1432    public function addrAppend($type, $addr)
1433    {
1434        $addresses = array();
1435        foreach ($addr as $address) {
1436            $addresses[] = $this->addrFormat($address);
1437        }
1438        return $type . ': ' . implode(', ', $addresses) . $this->LE;
1439    }
1440
1441    /**
1442     * Format an address for use in a message header.
1443     * @access public
1444     * @param array $addr A 2-element indexed array, element 0 containing an address, element 1 containing a name
1445     *      like array('joe@example.com', 'Joe User')
1446     * @return string
1447     */
1448    public function addrFormat($addr)
1449    {
1450        if (empty($addr[1])) { // No name provided
1451            return $this->secureHeader($addr[0]);
1452        } else {
1453            return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . ' <' . $this->secureHeader(
1454                $addr[0]
1455            ) . '>';
1456        }
1457    }
1458
1459    /**
1460     * Word-wrap message.
1461     * For use with mailers that do not automatically perform wrapping
1462     * and for quoted-printable encoded messages.
1463     * Original written by philippe.
1464     * @param string $message The message to wrap
1465     * @param integer $length The line length to wrap to
1466     * @param bool $qp_mode Whether to run in Quoted-Printable mode
1467     * @access public
1468     * @return string
1469     */
1470    public function wrapText($message, $length, $qp_mode = false)
1471    {
1472        $soft_break = ($qp_mode) ? sprintf(' =%s', $this->LE) : $this->LE;
1473        // If utf-8 encoding is used, we will need to make sure we don't
1474        // split multibyte characters when we wrap
1475        $is_utf8 = (strtolower($this->CharSet) == 'utf-8');
1476        $lelen = strlen($this->LE);
1477        $crlflen = strlen(self::CRLF);
1478
1479        $message = $this->fixEOL($message);
1480        if (substr($message, -$lelen) == $this->LE) {
1481            $message = substr($message, 0, -$lelen);
1482        }
1483
1484        $line = explode($this->LE, $message); // Magic. We know fixEOL uses $LE
1485        $message = '';
1486        for ($i = 0; $i < count($line); $i++) {
1487            $line_part = explode(' ', $line[$i]);
1488            $buf = '';
1489            for ($e = 0; $e < count($line_part); $e++) {
1490                $word = $line_part[$e];
1491                if ($qp_mode and (strlen($word) > $length)) {
1492                    $space_left = $length - strlen($buf) - $crlflen;
1493                    if ($e != 0) {
1494                        if ($space_left > 20) {
1495                            $len = $space_left;
1496                            if ($is_utf8) {
1497                                $len = $this->utf8CharBoundary($word, $len);
1498                            } elseif (substr($word, $len - 1, 1) == '=') {
1499                                $len--;
1500                            } elseif (substr($word, $len - 2, 1) == '=') {
1501                                $len -= 2;
1502                            }
1503                            $part = substr($word, 0, $len);
1504                            $word = substr($word, $len);
1505                            $buf .= ' ' . $part;
1506                            $message .= $buf . sprintf('=%s', self::CRLF);
1507                        } else {
1508                            $message .= $buf . $soft_break;
1509                        }
1510                        $buf = '';
1511                 

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