PageRenderTime 52ms CodeModel.GetById 6ms app.highlight 27ms RepoModel.GetById 2ms app.codeStats 1ms

/vendor/phpmailer/phpmailer/class.phpmailer.php

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

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