PageRenderTime 85ms CodeModel.GetById 47ms app.highlight 26ms RepoModel.GetById 1ms app.codeStats 1ms

/webroot/lib/PHPMailer/class.phpmailer.php

https://github.com/jhonsegurag/SI
PHP | 3465 lines | 2020 code | 230 blank | 1215 comment | 339 complexity | fd252aff9feaf27318725ca3aa27204a 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     * Set to 0 to not wrap. A useful value here is 78, for RFC2822 section 2.1.1 compliance.
 153     * @type integer
 154     */
 155    public $WordWrap = 0;
 156
 157    /**
 158     * Which method to use to send mail.
 159     * Options: "mail", "sendmail", or "smtp".
 160     * @type string
 161     */
 162    public $Mailer = 'mail';
 163
 164    /**
 165     * The path to the sendmail program.
 166     * @type string
 167     */
 168    public $Sendmail = '/usr/sbin/sendmail';
 169
 170    /**
 171     * Whether mail() uses a fully sendmail-compatible MTA.
 172     * One which supports sendmail's "-oi -f" options.
 173     * @type boolean
 174     */
 175    public $UseSendmailOptions = true;
 176
 177    /**
 178     * Path to PHPMailer plugins.
 179     * Useful if the SMTP class is not in the PHP include path.
 180     * @type string
 181     * @deprecated Should not be needed now there is an autoloader.
 182     */
 183    public $PluginDir = '';
 184
 185    /**
 186     * The email address that a reading confirmation should be sent to.
 187     * @type string
 188     */
 189    public $ConfirmReadingTo = '';
 190
 191    /**
 192     * The hostname to use in Message-Id and Received headers
 193     * and as default HELO string.
 194     * If empty, the value returned
 195     * by SERVER_NAME is used or 'localhost.localdomain'.
 196     * @type string
 197     */
 198    public $Hostname = '';
 199
 200    /**
 201     * An ID to be used in the Message-Id header.
 202     * If empty, a unique id will be generated.
 203     * @type string
 204     */
 205    public $MessageID = '';
 206
 207    /**
 208     * The message Date to be used in the Date header.
 209     * If empty, the current date will be added.
 210     * @type string
 211     */
 212    public $MessageDate = '';
 213
 214    /**
 215     * SMTP hosts.
 216     * Either a single hostname or multiple semicolon-delimited hostnames.
 217     * You can also specify a different port
 218     * for each host by using this format: [hostname:port]
 219     * (e.g. "smtp1.example.com:25;smtp2.example.com").
 220     * You can also specify encryption type, for example:
 221     * (e.g. "tls://smtp1.example.com:587;ssl://smtp2.example.com:465").
 222     * Hosts will be tried in order.
 223     * @type string
 224     */
 225    public $Host = 'localhost';
 226
 227    /**
 228     * The default SMTP server port.
 229     * @type integer
 230     * @TODO Why is this needed when the SMTP class takes care of it?
 231     */
 232    public $Port = 25;
 233
 234    /**
 235     * The SMTP HELO of the message.
 236     * Default is $Hostname.
 237     * @type string
 238     * @see PHPMailer::$Hostname
 239     */
 240    public $Helo = '';
 241
 242    /**
 243     * The secure connection prefix.
 244     * Options: "", "ssl" or "tls"
 245     * @type string
 246     */
 247    public $SMTPSecure = '';
 248
 249    /**
 250     * Whether to use SMTP authentication.
 251     * Uses the Username and Password properties.
 252     * @type boolean
 253     * @see PHPMailer::$Username
 254     * @see PHPMailer::$Password
 255     */
 256    public $SMTPAuth = false;
 257
 258    /**
 259     * SMTP username.
 260     * @type string
 261     */
 262    public $Username = '';
 263
 264    /**
 265     * SMTP password.
 266     * @type string
 267     */
 268    public $Password = '';
 269
 270    /**
 271     * SMTP auth type.
 272     * Options are LOGIN (default), PLAIN, NTLM, CRAM-MD5
 273     * @type string
 274     */
 275    public $AuthType = '';
 276
 277    /**
 278     * SMTP realm.
 279     * Used for NTLM auth
 280     * @type string
 281     */
 282    public $Realm = '';
 283
 284    /**
 285     * SMTP workstation.
 286     * Used for NTLM auth
 287     * @type string
 288     */
 289    public $Workstation = '';
 290
 291    /**
 292     * The SMTP server timeout in seconds.
 293     * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
 294     * @type integer
 295     */
 296    public $Timeout = 300;
 297
 298    /**
 299     * SMTP class debug output mode.
 300     * Debug output level.
 301     * Options:
 302     * * `0` No output
 303     * * `1` Commands
 304     * * `2` Data and commands
 305     * * `3` As 2 plus connection status
 306     * * `4` Low-level data output
 307     * @type integer
 308     * @see SMTP::$do_debug
 309     */
 310    public $SMTPDebug = 0;
 311
 312    /**
 313     * How to handle debug output.
 314     * Options:
 315     * * `echo` Output plain-text as-is, appropriate for CLI
 316     * * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output
 317     * * `error_log` Output to error log as configured in php.ini
 318     *
 319     * Alternatively, you can provide a callable expecting two params: a message string and the debug level:
 320     * <code>
 321     * $mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
 322     * </code>
 323     * @type string|callable
 324     * @see SMTP::$Debugoutput
 325     */
 326    public $Debugoutput = 'echo';
 327
 328    /**
 329     * Whether to keep SMTP connection open after each message.
 330     * If this is set to true then to close the connection
 331     * requires an explicit call to smtpClose().
 332     * @type boolean
 333     */
 334    public $SMTPKeepAlive = false;
 335
 336    /**
 337     * Whether to split multiple to addresses into multiple messages
 338     * or send them all in one message.
 339     * @type boolean
 340     */
 341    public $SingleTo = false;
 342
 343    /**
 344     * Storage for addresses when SingleTo is enabled.
 345     * @type array
 346     * @TODO This should really not be public
 347     */
 348    public $SingleToArray = array();
 349
 350    /**
 351     * Whether to generate VERP addresses on send.
 352     * Only applicable when sending via SMTP.
 353     * @link http://en.wikipedia.org/wiki/Variable_envelope_return_path
 354     * @link http://www.postfix.org/VERP_README.html Postfix VERP info
 355     * @type boolean
 356     */
 357    public $do_verp = false;
 358
 359    /**
 360     * Whether to allow sending messages with an empty body.
 361     * @type boolean
 362     */
 363    public $AllowEmpty = false;
 364
 365    /**
 366     * The default line ending.
 367     * @note The default remains "\n". We force CRLF where we know
 368     *        it must be used via self::CRLF.
 369     * @type string
 370     */
 371    public $LE = "\n";
 372
 373    /**
 374     * DKIM selector.
 375     * @type string
 376     */
 377    public $DKIM_selector = '';
 378
 379    /**
 380     * DKIM Identity.
 381     * Usually the email address used as the source of the email
 382     * @type string
 383     */
 384    public $DKIM_identity = '';
 385
 386    /**
 387     * DKIM passphrase.
 388     * Used if your key is encrypted.
 389     * @type string
 390     */
 391    public $DKIM_passphrase = '';
 392
 393    /**
 394     * DKIM signing domain name.
 395     * @example 'example.com'
 396     * @type string
 397     */
 398    public $DKIM_domain = '';
 399
 400    /**
 401     * DKIM private key file path.
 402     * @type string
 403     */
 404    public $DKIM_private = '';
 405
 406    /**
 407     * Callback Action function name.
 408     *
 409     * The function that handles the result of the send email action.
 410     * It is called out by send() for each email sent.
 411     *
 412     * Value can be any php callable: http://www.php.net/is_callable
 413     *
 414     * Parameters:
 415     *   boolean $result        result of the send action
 416     *   string  $to            email address of the recipient
 417     *   string  $cc            cc email addresses
 418     *   string  $bcc           bcc email addresses
 419     *   string  $subject       the subject
 420     *   string  $body          the email body
 421     *   string  $from          email address of sender
 422     * @type string
 423     */
 424    public $action_function = '';
 425
 426    /**
 427     * What to put in the X-Mailer header.
 428     * Options: An empty string for PHPMailer default, whitespace for none, or a string to use
 429     * @type string
 430     */
 431    public $XMailer = '';
 432
 433    /**
 434     * An instance of the SMTP sender class.
 435     * @type SMTP
 436     * @access protected
 437     */
 438    protected $smtp = null;
 439
 440    /**
 441     * The array of 'to' addresses.
 442     * @type array
 443     * @access protected
 444     */
 445    protected $to = array();
 446
 447    /**
 448     * The array of 'cc' addresses.
 449     * @type array
 450     * @access protected
 451     */
 452    protected $cc = array();
 453
 454    /**
 455     * The array of 'bcc' addresses.
 456     * @type array
 457     * @access protected
 458     */
 459    protected $bcc = array();
 460
 461    /**
 462     * The array of reply-to names and addresses.
 463     * @type array
 464     * @access protected
 465     */
 466    protected $ReplyTo = array();
 467
 468    /**
 469     * An array of all kinds of addresses.
 470     * Includes all of $to, $cc, $bcc, $replyto
 471     * @type array
 472     * @access protected
 473     */
 474    protected $all_recipients = array();
 475
 476    /**
 477     * The array of attachments.
 478     * @type array
 479     * @access protected
 480     */
 481    protected $attachment = array();
 482
 483    /**
 484     * The array of custom headers.
 485     * @type array
 486     * @access protected
 487     */
 488    protected $CustomHeader = array();
 489
 490    /**
 491     * The most recent Message-ID (including angular brackets).
 492     * @type string
 493     * @access protected
 494     */
 495    protected $lastMessageID = '';
 496
 497    /**
 498     * The message's MIME type.
 499     * @type string
 500     * @access protected
 501     */
 502    protected $message_type = '';
 503
 504    /**
 505     * The array of MIME boundary strings.
 506     * @type array
 507     * @access protected
 508     */
 509    protected $boundary = array();
 510
 511    /**
 512     * The array of available languages.
 513     * @type array
 514     * @access protected
 515     */
 516    protected $language = array();
 517
 518    /**
 519     * The number of errors encountered.
 520     * @type integer
 521     * @access protected
 522     */
 523    protected $error_count = 0;
 524
 525    /**
 526     * The S/MIME certificate file path.
 527     * @type string
 528     * @access protected
 529     */
 530    protected $sign_cert_file = '';
 531
 532    /**
 533     * The S/MIME key file path.
 534     * @type string
 535     * @access protected
 536     */
 537    protected $sign_key_file = '';
 538
 539    /**
 540     * The S/MIME password for the key.
 541     * Used only if the key is encrypted.
 542     * @type string
 543     * @access protected
 544     */
 545    protected $sign_key_pass = '';
 546
 547    /**
 548     * Whether to throw exceptions for errors.
 549     * @type boolean
 550     * @access protected
 551     */
 552    protected $exceptions = false;
 553
 554    /**
 555     * Error severity: message only, continue processing.
 556     */
 557    const STOP_MESSAGE = 0;
 558
 559    /**
 560     * Error severity: message, likely ok to continue processing.
 561     */
 562    const STOP_CONTINUE = 1;
 563
 564    /**
 565     * Error severity: message, plus full stop, critical error reached.
 566     */
 567    const STOP_CRITICAL = 2;
 568
 569    /**
 570     * SMTP RFC standard line ending.
 571     */
 572    const CRLF = "\r\n";
 573
 574    /**
 575     * Constructor.
 576     * @param boolean $exceptions Should we throw external exceptions?
 577     */
 578    public function __construct($exceptions = false)
 579    {
 580        $this->exceptions = (boolean)$exceptions;
 581    }
 582
 583    /**
 584     * Destructor.
 585     */
 586    public function __destruct()
 587    {
 588        if ($this->Mailer == 'smtp') { //close any open SMTP connection nicely
 589            $this->smtpClose();
 590        }
 591    }
 592
 593    /**
 594     * Call mail() in a safe_mode-aware fashion.
 595     * Also, unless sendmail_path points to sendmail (or something that
 596     * claims to be sendmail), don't pass params (not a perfect fix,
 597     * but it will do)
 598     * @param string $to To
 599     * @param string $subject Subject
 600     * @param string $body Message Body
 601     * @param string $header Additional Header(s)
 602     * @param string $params Params
 603     * @access private
 604     * @return boolean
 605     */
 606    private function mailPassthru($to, $subject, $body, $header, $params)
 607    {
 608        //Check overloading of mail function to avoid double-encoding
 609        if (ini_get('mbstring.func_overload') & 1) {
 610            $subject = $this->secureHeader($subject);
 611        } else {
 612            $subject = $this->encodeHeader($this->secureHeader($subject));
 613        }
 614        if (ini_get('safe_mode') || !($this->UseSendmailOptions)) {
 615            $result = @mail($to, $subject, $body, $header);
 616        } else {
 617            $result = @mail($to, $subject, $body, $header, $params);
 618        }
 619        return $result;
 620    }
 621
 622    /**
 623     * Output debugging info via user-defined method.
 624     * Only generates output if SMTP debug output is enabled (@see SMTP::$do_debug).
 625     * @see PHPMailer::$Debugoutput
 626     * @see PHPMailer::$SMTPDebug
 627     * @param string $str
 628     */
 629    protected function edebug($str)
 630    {
 631        if ($this->SMTPDebug <= 0) {
 632            return;
 633        }
 634        //Avoid clash with built-in function names
 635        if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
 636            call_user_func($this->Debugoutput, $str, $this->SMTPDebug);
 637            return;
 638        }
 639        switch ($this->Debugoutput) {
 640            case 'error_log':
 641                //Don't output, just log
 642                error_log($str);
 643                break;
 644            case 'html':
 645                //Cleans up output a bit for a better looking, HTML-safe output
 646                echo htmlentities(
 647                    preg_replace('/[\r\n]+/', '', $str),
 648                    ENT_QUOTES,
 649                    'UTF-8'
 650                )
 651                . "<br>\n";
 652                break;
 653            case 'echo':
 654            default:
 655                //Normalize line breaks
 656                $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
 657                echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
 658                    "\n",
 659                    "\n                   \t                  ",
 660                    trim($str)
 661                ) . "\n";
 662        }
 663    }
 664
 665    /**
 666     * Sets message type to HTML or plain.
 667     * @param boolean $isHtml True for HTML mode.
 668     * @return void
 669     */
 670    public function isHTML($isHtml = true)
 671    {
 672        if ($isHtml) {
 673            $this->ContentType = 'text/html';
 674        } else {
 675            $this->ContentType = 'text/plain';
 676        }
 677    }
 678
 679    /**
 680     * Send messages using SMTP.
 681     * @return void
 682     */
 683    public function isSMTP()
 684    {
 685        $this->Mailer = 'smtp';
 686    }
 687
 688    /**
 689     * Send messages using PHP's mail() function.
 690     * @return void
 691     */
 692    public function isMail()
 693    {
 694        $this->Mailer = 'mail';
 695    }
 696
 697    /**
 698     * Send messages using $Sendmail.
 699     * @return void
 700     */
 701    public function isSendmail()
 702    {
 703        $ini_sendmail_path = ini_get('sendmail_path');
 704
 705        if (!stristr($ini_sendmail_path, 'sendmail')) {
 706            $this->Sendmail = '/usr/sbin/sendmail';
 707        } else {
 708            $this->Sendmail = $ini_sendmail_path;
 709        }
 710        $this->Mailer = 'sendmail';
 711    }
 712
 713    /**
 714     * Send messages using qmail.
 715     * @return void
 716     */
 717    public function isQmail()
 718    {
 719        $ini_sendmail_path = ini_get('sendmail_path');
 720
 721        if (!stristr($ini_sendmail_path, 'qmail')) {
 722            $this->Sendmail = '/var/qmail/bin/qmail-inject';
 723        } else {
 724            $this->Sendmail = $ini_sendmail_path;
 725        }
 726        $this->Mailer = 'qmail';
 727    }
 728
 729    /**
 730     * Add a "To" address.
 731     * @param string $address
 732     * @param string $name
 733     * @return boolean true on success, false if address already used
 734     */
 735    public function addAddress($address, $name = '')
 736    {
 737        return $this->addAnAddress('to', $address, $name);
 738    }
 739
 740    /**
 741     * Add a "CC" address.
 742     * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
 743     * @param string $address
 744     * @param string $name
 745     * @return boolean true on success, false if address already used
 746     */
 747    public function addCC($address, $name = '')
 748    {
 749        return $this->addAnAddress('cc', $address, $name);
 750    }
 751
 752    /**
 753     * Add a "BCC" address.
 754     * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
 755     * @param string $address
 756     * @param string $name
 757     * @return boolean true on success, false if address already used
 758     */
 759    public function addBCC($address, $name = '')
 760    {
 761        return $this->addAnAddress('bcc', $address, $name);
 762    }
 763
 764    /**
 765     * Add a "Reply-to" address.
 766     * @param string $address
 767     * @param string $name
 768     * @return boolean
 769     */
 770    public function addReplyTo($address, $name = '')
 771    {
 772        return $this->addAnAddress('Reply-To', $address, $name);
 773    }
 774
 775    /**
 776     * Add an address to one of the recipient arrays.
 777     * Addresses that have been added already return false, but do not throw exceptions
 778     * @param string $kind One of 'to', 'cc', 'bcc', 'ReplyTo'
 779     * @param string $address The email address to send to
 780     * @param string $name
 781     * @throws phpmailerException
 782     * @return boolean true on success, false if address already used or invalid in some way
 783     * @access protected
 784     */
 785    protected function addAnAddress($kind, $address, $name = '')
 786    {
 787        if (!preg_match('/^(to|cc|bcc|Reply-To)$/', $kind)) {
 788            $this->setError($this->lang('Invalid recipient array') . ': ' . $kind);
 789            $this->edebug($this->lang('Invalid recipient array') . ': ' . $kind);
 790            if ($this->exceptions) {
 791                throw new phpmailerException('Invalid recipient array: ' . $kind);
 792            }
 793            return false;
 794        }
 795        $address = trim($address);
 796        $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
 797        if (!$this->validateAddress($address)) {
 798            $this->setError($this->lang('invalid_address') . ': ' . $address);
 799            $this->edebug($this->lang('invalid_address') . ': ' . $address);
 800            if ($this->exceptions) {
 801                throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
 802            }
 803            return false;
 804        }
 805        if ($kind != 'Reply-To') {
 806            if (!isset($this->all_recipients[strtolower($address)])) {
 807                array_push($this->$kind, array($address, $name));
 808                $this->all_recipients[strtolower($address)] = true;
 809                return true;
 810            }
 811        } else {
 812            if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
 813                $this->ReplyTo[strtolower($address)] = array($address, $name);
 814                return true;
 815            }
 816        }
 817        return false;
 818    }
 819
 820    /**
 821     * Set the From and FromName properties.
 822     * @param string $address
 823     * @param string $name
 824     * @param boolean $auto Whether to also set the Sender address, defaults to true
 825     * @throws phpmailerException
 826     * @return boolean
 827     */
 828    public function setFrom($address, $name = '', $auto = true)
 829    {
 830        $address = trim($address);
 831        $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
 832        if (!$this->validateAddress($address)) {
 833            $this->setError($this->lang('invalid_address') . ': ' . $address);
 834            $this->edebug($this->lang('invalid_address') . ': ' . $address);
 835            if ($this->exceptions) {
 836                throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
 837            }
 838            return false;
 839        }
 840        $this->From = $address;
 841        $this->FromName = $name;
 842        if ($auto) {
 843            if (empty($this->Sender)) {
 844                $this->Sender = $address;
 845            }
 846        }
 847        return true;
 848    }
 849
 850    /**
 851     * Return the Message-ID header of the last email.
 852     * Technically this is the value from the last time the headers were created,
 853     * but it's also the message ID of the last sent message except in
 854     * pathological cases.
 855     * @return string
 856     */
 857    public function getLastMessageID()
 858    {
 859        return $this->lastMessageID;
 860    }
 861
 862    /**
 863     * Check that a string looks like an email address.
 864     * @param string $address The email address to check
 865     * @param string $patternselect A selector for the validation pattern to use :
 866     * * `auto` Pick strictest one automatically;
 867     * * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14;
 868     * * `pcre` Use old PCRE implementation;
 869     * * `php` Use PHP built-in FILTER_VALIDATE_EMAIL; same as pcre8 but does not allow 'dotless' domains;
 870     * * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements.
 871     * * `noregex` Don't use a regex: super fast, really dumb.
 872     * @return boolean
 873     * @static
 874     * @access public
 875     */
 876    public static function validateAddress($address, $patternselect = 'auto')
 877    {
 878        if (!$patternselect or $patternselect == 'auto') {
 879            //Check this constant first so it works when extension_loaded() is disabled by safe mode
 880            //Constant was added in PHP 5.2.4
 881            if (defined('PCRE_VERSION')) {
 882                //This pattern can get stuck in a recursive loop in PCRE <= 8.0.2
 883                if (version_compare(PCRE_VERSION, '8.0.3') >= 0) {
 884                    $patternselect = 'pcre8';
 885                } else {
 886                    $patternselect = 'pcre';
 887                }
 888            } elseif (function_exists('extension_loaded') and extension_loaded('pcre')) {
 889                //Fall back to older PCRE
 890                $patternselect = 'pcre';
 891            } else {
 892                //Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
 893                if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
 894                    $patternselect = 'php';
 895                } else {
 896                    $patternselect = 'noregex';
 897                }
 898            }
 899        }
 900        switch ($patternselect) {
 901            case 'pcre8':
 902                /**
 903                 * Uses the same RFC5322 regex on which FILTER_VALIDATE_EMAIL is based, but allows dotless domains.
 904                 * @link http://squiloople.com/2009/12/20/email-address-validation/
 905                 * @copyright 2009-2010 Michael Rushton
 906                 * Feel free to use and redistribute this code. But please keep this copyright notice.
 907                 */
 908                return (boolean)preg_match(
 909                    '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
 910                    '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
 911                    '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
 912                    '([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
 913                    '(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
 914                    '(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
 915                    '|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
 916                    '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
 917                    '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
 918                    $address
 919                );
 920            case 'pcre':
 921                //An older regex that doesn't need a recent PCRE
 922                return (boolean)preg_match(
 923                    '/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' .
 924                    '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' .
 925                    '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' .
 926                    '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' .
 927                    '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' .
 928                    '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' .
 929                    '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' .
 930                    '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' .
 931                    '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
 932                    '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
 933                    $address
 934                );
 935            case 'html5':
 936                /**
 937                 * This is the pattern used in the HTML5 spec for validation of 'email' type form input elements.
 938                 * @link http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state-(type=email)
 939                 */
 940                return (boolean)preg_match(
 941                    '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' .
 942                    '[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD',
 943                    $address
 944                );
 945            case 'noregex':
 946                //No PCRE! Do something _very_ approximate!
 947                //Check the address is 3 chars or longer and contains an @ that's not the first or last char
 948                return (strlen($address) >= 3
 949                    and strpos($address, '@') >= 1
 950                    and strpos($address, '@') != strlen($address) - 1);
 951            case 'php':
 952            default:
 953                return (boolean)filter_var($address, FILTER_VALIDATE_EMAIL);
 954        }
 955    }
 956
 957    /**
 958     * Create a message and send it.
 959     * Uses the sending method specified by $Mailer.
 960     * @throws phpmailerException
 961     * @return boolean false on error - See the ErrorInfo property for details of the error.
 962     */
 963    public function send()
 964    {
 965        try {
 966            if (!$this->preSend()) {
 967                return false;
 968            }
 969            return $this->postSend();
 970        } catch (phpmailerException $exc) {
 971            $this->mailHeader = '';
 972            $this->setError($exc->getMessage());
 973            if ($this->exceptions) {
 974                throw $exc;
 975            }
 976            return false;
 977        }
 978    }
 979
 980    /**
 981     * Prepare a message for sending.
 982     * @throws phpmailerException
 983     * @return boolean
 984     */
 985    public function preSend()
 986    {
 987        try {
 988            $this->mailHeader = '';
 989            if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
 990                throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL);
 991            }
 992
 993            // Set whether the message is multipart/alternative
 994            if (!empty($this->AltBody)) {
 995                $this->ContentType = 'multipart/alternative';
 996            }
 997
 998            $this->error_count = 0; // reset errors
 999            $this->setMessageType();
1000            // Refuse to send an empty message unless we are specifically allowing it
1001            if (!$this->AllowEmpty and empty($this->Body)) {
1002                throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
1003            }
1004
1005            $this->MIMEHeader = $this->createHeader();
1006            $this->MIMEBody = $this->createBody();
1007
1008            // To capture the complete message when using mail(), create
1009            // an extra header list which createHeader() doesn't fold in
1010            if ($this->Mailer == 'mail') {
1011                if (count($this->to) > 0) {
1012                    $this->mailHeader .= $this->addrAppend('To', $this->to);
1013                } else {
1014                    $this->mailHeader .= $this->headerLine('To', 'undisclosed-recipients:;');
1015                }
1016                $this->mailHeader .= $this->headerLine(
1017                    'Subject',
1018                    $this->encodeHeader($this->secureHeader(trim($this->Subject)))
1019                );
1020            }
1021
1022            // Sign with DKIM if enabled
1023            if (!empty($this->DKIM_domain)
1024                && !empty($this->DKIM_private)
1025                && !empty($this->DKIM_selector)
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        $li…

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