PageRenderTime 11ms CodeModel.GetById 4ms app.highlight 31ms RepoModel.GetById 1ms app.codeStats 0ms

/mailer/class.phpmailer.php

https://bitbucket.org/svkem2/courseplanning
PHP | 3455 lines | 2027 code | 230 blank | 1198 comment | 344 complexity | eb35626641e227a9e6eaef1f1c66d52e MD5 | raw file

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

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

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