2 /*~ class.phpmailer.php
3 .---------------------------------------------------------------------------.
4 | Software: PHPMailer - PHP email class |
6 | Contact: via sourceforge.net support pages (also www.codeworxtech.com) |
7 | Info: http://phpmailer.sourceforge.net |
8 | Support: http://sourceforge.net/projects/phpmailer/ |
9 | ------------------------------------------------------------------------- |
10 | Author: Andy Prevost (project admininistrator) |
11 | Author: Brent R. Matzelle (original founder) |
12 | Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. |
13 | Copyright (c) 2001-2003, Brent R. Matzelle |
14 | ------------------------------------------------------------------------- |
15 | License: Distributed under the Lesser General Public License (LGPL) |
16 | http://www.gnu.org/copyleft/lesser.html |
17 | This program is distributed in the hope that it will be useful - WITHOUT |
18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
19 | FITNESS FOR A PARTICULAR PURPOSE. |
20 | ------------------------------------------------------------------------- |
21 | We offer a number of paid services (www.codeworxtech.com): |
22 | - Web Hosting on highly optimized fast and secure servers |
23 | - Technology Consulting |
24 | - Oursourcing (highly qualified programmers and graphic designers) |
25 '---------------------------------------------------------------------------'
28 * PHPMailer - PHP email transport class
29 * NOTE: Designed for use with PHP version 5 and up
31 * @author Andy Prevost
32 * @copyright 2004 - 2008 Andy Prevost
37 /////////////////////////////////////////////////
39 /////////////////////////////////////////////////
42 * Email priority (1 = High, 3 = Normal, 5 = low).
48 * Sets the CharSet of the message.
51 public $CharSet = 'iso-8859-1';
54 * Sets the Content-type of the message.
57 public $ContentType = 'text/plain';
60 * Sets the Encoding of the message. Options for this are "8bit",
61 * "7bit", "binary", "base64", and "quoted-printable".
64 public $Encoding = '8bit';
67 * Holds the most recent mailer error message.
70 public $ErrorInfo = '';
73 * Sets the From email address for the message.
76 public $From = 'root@localhost';
79 * Sets the From name of the message.
82 public $FromName = 'Root User';
85 * Sets the Sender email (Return-Path) of the message. If not empty,
86 * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
92 * Sets the Subject of the message.
98 * Sets the Body of the message. This can be either an HTML or text body.
99 * If HTML then run IsHTML(true).
105 * Sets the text-only body of the message. This automatically sets the
106 * email to multipart/alternative. This body can be read by mail
107 * clients that do not have HTML email capability such as mutt. Clients
108 * that can read HTML will view the normal Body.
111 public $AltBody = '';
114 * Sets word wrapping on the body of the message to a given number of
118 public $WordWrap = 0;
121 * Method to send mail: ("mail", "sendmail", or "smtp").
124 public $Mailer = 'mail';
127 * Sets the path of the sendmail program.
130 public $Sendmail = '/usr/sbin/sendmail';
133 * Path to PHPMailer plugins. This is now only useful if the SMTP class
134 * is in a different directory than the PHP include path.
137 public $PluginDir = '';
140 * Holds PHPMailer version.
143 public $Version = "2.3";
146 * Sets the email address that a reading confirmation will be sent.
149 public $ConfirmReadingTo = '';
152 * Sets the hostname to use in Message-Id and Received headers
153 * and as default HELO string. If empty, the value returned
154 * by SERVER_NAME is used or 'localhost.localdomain'.
157 public $Hostname = '';
160 * Sets the message ID to be used in the Message-Id header.
161 * If empty, a unique id will be generated.
164 public $MessageID = '';
166 /////////////////////////////////////////////////
167 // PROPERTIES FOR SMTP
168 /////////////////////////////////////////////////
171 * Sets the SMTP hosts. All hosts must be separated by a
172 * semicolon. You can also specify a different port
173 * for each host by using this format: [hostname:port]
174 * (e.g. "smtp1.example.com:25;smtp2.example.com").
175 * Hosts will be tried in order.
178 public $Host = 'localhost';
181 * Sets the default SMTP server port.
187 * Sets the SMTP HELO of the message (Default is $Hostname).
193 * Sets connection prefix.
194 * Options are "", "ssl" or "tls"
197 public $SMTPSecure = "";
200 * Sets SMTP authentication. Utilizes the Username and Password variables.
203 public $SMTPAuth = false;
206 * Sets SMTP username.
209 public $Username = '';
212 * Sets SMTP password.
215 public $Password = '';
218 * Sets the SMTP server timeout in seconds. This function will not
219 * work with the win32 version.
222 public $Timeout = 10;
225 * Sets SMTP class debugging on or off.
228 public $SMTPDebug = false;
231 * Prevents the SMTP connection from being closed after each mail
232 * sending. If this is set to true then to close the connection
233 * requires an explicit call to SmtpClose().
236 public $SMTPKeepAlive = false;
239 * Provides the ability to have the TO field process individual
240 * emails, instead of sending to entire TO addresses
243 public $SingleTo = false;
246 * Provides the ability to change the line ending
251 /////////////////////////////////////////////////
252 // PROPERTIES, PRIVATE
253 /////////////////////////////////////////////////
255 private $smtp = NULL;
256 private $to = array();
257 private $cc = array();
258 private $bcc = array();
259 private $ReplyTo = array();
260 private $attachment = array();
261 private $CustomHeader = array();
262 private $message_type = '';
263 private $boundary = array();
264 private $language = array();
265 private $error_count = 0;
266 private $sign_cert_file = "";
267 private $sign_key_file = "";
268 private $sign_key_pass = "";
270 /////////////////////////////////////////////////
271 // METHODS, VARIABLES
272 /////////////////////////////////////////////////
275 * Sets message type to HTML.
279 public function IsHTML($bool) {
281 $this->ContentType = 'text/html';
283 $this->ContentType = 'text/plain';
288 * Sets Mailer to send message using SMTP.
291 public function IsSMTP() {
292 $this->Mailer = 'smtp';
296 * Sets Mailer to send message using PHP mail() function.
299 public function IsMail() {
300 $this->Mailer = 'mail';
304 * Sets Mailer to send message using the $Sendmail program.
307 public function IsSendmail() {
308 $this->Mailer = 'sendmail';
312 * Sets Mailer to send message using the qmail MTA.
315 public function IsQmail() {
316 $this->Sendmail = '/var/qmail/bin/sendmail';
317 $this->Mailer = 'sendmail';
320 /////////////////////////////////////////////////
321 // METHODS, RECIPIENTS
322 /////////////////////////////////////////////////
325 * Adds a "To" address.
326 * @param string $address
327 * @param string $name
330 public function AddAddress($address, $name = '') {
331 $cur = count($this->to);
332 $this->to[$cur][0] = trim($address);
333 $this->to[$cur][1] = $name;
337 * Adds a "Cc" address. Note: this function works
338 * with the SMTP mailer on win32, not with the "mail"
340 * @param string $address
341 * @param string $name
344 public function AddCC($address, $name = '') {
345 $cur = count($this->cc);
346 $this->cc[$cur][0] = trim($address);
347 $this->cc[$cur][1] = $name;
351 * Adds a "Bcc" address. Note: this function works
352 * with the SMTP mailer on win32, not with the "mail"
354 * @param string $address
355 * @param string $name
358 public function AddBCC($address, $name = '') {
359 $cur = count($this->bcc);
360 $this->bcc[$cur][0] = trim($address);
361 $this->bcc[$cur][1] = $name;
365 * Adds a "Reply-to" address.
366 * @param string $address
367 * @param string $name
370 public function AddReplyTo($address, $name = '') {
371 $cur = count($this->ReplyTo);
372 $this->ReplyTo[$cur][0] = trim($address);
373 $this->ReplyTo[$cur][1] = $name;
376 /////////////////////////////////////////////////
377 // METHODS, MAIL SENDING
378 /////////////////////////////////////////////////
381 * Creates message and assigns Mailer. If the message is
382 * not sent successfully then it returns false. Use the ErrorInfo
383 * variable to view description of the error.
386 public function Send() {
391 if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
392 $this->SetError($this->Lang('provide_address'));
396 /* Set whether the message is multipart/alternative */
397 if(!empty($this->AltBody)) {
398 $this->ContentType = 'multipart/alternative';
401 $this->error_count = 0; // reset errors
402 $this->SetMessageType();
403 $header .= $this->CreateHeader();
404 $body = $this->CreateBody();
410 /* Choose the mailer */
411 switch($this->Mailer) {
413 $result = $this->SendmailSend($header, $body);
416 $result = $this->SmtpSend($header, $body);
419 $result = $this->MailSend($header, $body);
422 $result = $this->MailSend($header, $body);
424 //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
433 * Sends mail using the $Sendmail program.
437 public function SendmailSend($header, $body) {
438 if ($this->Sender != '') {
439 $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
441 $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
444 if(!@$mail = popen($sendmail, 'w')) {
445 $this->SetError($this->Lang('execute') . $this->Sendmail);
449 fputs($mail, $header);
452 $result = pclose($mail);
453 if (version_compare(phpversion(), '4.2.3') == -1) {
454 $result = $result >> 8 & 0xFF;
457 $this->SetError($this->Lang('execute') . $this->Sendmail);
465 * Sends mail using the PHP mail() function.
469 public function MailSend($header, $body) {
472 for($i = 0; $i < count($this->to); $i++) {
473 if($i != 0) { $to .= ', '; }
474 $to .= $this->AddrFormat($this->to[$i]);
477 $toArr = split(',', $to);
479 $params = sprintf("-oi -f %s", $this->Sender);
480 if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) {
481 $old_from = ini_get('sendmail_from');
482 ini_set('sendmail_from', $this->Sender);
483 if ($this->SingleTo === true && count($toArr) > 1) {
484 foreach ($toArr as $key => $val) {
485 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
488 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
491 if ($this->SingleTo === true && count($toArr) > 1) {
492 foreach ($toArr as $key => $val) {
493 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
496 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
500 if (isset($old_from)) {
501 ini_set('sendmail_from', $old_from);
505 $this->SetError($this->Lang('instantiate'));
513 * Sends mail via SMTP using PhpSMTP (Author:
514 * Chris Ryan). Returns bool. Returns false if there is a
515 * bad MAIL FROM, RCPT, or DATA input.
519 public function SmtpSend($header, $body) {
520 include_once($this->PluginDir . 'class.smtp.php');
524 if(!$this->SmtpConnect()) {
528 $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
529 if(!$this->smtp->Mail($smtp_from)) {
530 $error = $this->Lang('from_failed') . $smtp_from;
531 $this->SetError($error);
532 $this->smtp->Reset();
536 /* Attempt to send attach all recipients */
537 for($i = 0; $i < count($this->to); $i++) {
538 if(!$this->smtp->Recipient($this->to[$i][0])) {
539 $bad_rcpt[] = $this->to[$i][0];
542 for($i = 0; $i < count($this->cc); $i++) {
543 if(!$this->smtp->Recipient($this->cc[$i][0])) {
544 $bad_rcpt[] = $this->cc[$i][0];
547 for($i = 0; $i < count($this->bcc); $i++) {
548 if(!$this->smtp->Recipient($this->bcc[$i][0])) {
549 $bad_rcpt[] = $this->bcc[$i][0];
553 if(count($bad_rcpt) > 0) { // Create error message
554 for($i = 0; $i < count($bad_rcpt); $i++) {
558 $error .= $bad_rcpt[$i];
560 $error = $this->Lang('recipients_failed') . $error;
561 $this->SetError($error);
562 $this->smtp->Reset();
566 if(!$this->smtp->Data($header . $body)) {
567 $this->SetError($this->Lang('data_not_accepted'));
568 $this->smtp->Reset();
571 if($this->SMTPKeepAlive == true) {
572 $this->smtp->Reset();
581 * Initiates a connection to an SMTP server. Returns false if the
586 public function SmtpConnect() {
587 if($this->smtp == NULL) {
588 $this->smtp = new SMTP();
591 $this->smtp->do_debug = $this->SMTPDebug;
592 $hosts = explode(';', $this->Host);
594 $connection = ($this->smtp->Connected());
596 /* Retry while there is no connection */
597 while($index < count($hosts) && $connection == false) {
599 if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
600 $host = $hostinfo[1];
601 $port = $hostinfo[2];
603 $host = $hosts[$index];
607 $tls = ($this->SMTPSecure == 'tls');
608 $ssl = ($this->SMTPSecure == 'ssl');
610 if($this->smtp->Connect(($ssl ? 'ssl://':'').$host, $port, $this->Timeout)) {
612 $hello = ($this->Helo != '' ? $this->Helo : $this->ServerHostname());
613 $this->smtp->Hello($hello);
616 if(!$this->smtp->StartTLS()) {
617 $this->SetError($this->Lang("tls"));
618 $this->smtp->Reset();
622 //We must resend HELLO after tls negociation
623 $this->smtp->Hello($hello);
627 if($this->SMTPAuth) {
628 if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
629 $this->SetError($this->Lang('authenticate'));
630 $this->smtp->Reset();
638 $this->SetError($this->Lang('connect_host'));
645 * Closes the active SMTP session if one exists.
648 public function SmtpClose() {
649 if($this->smtp != NULL) {
650 if($this->smtp->Connected()) {
652 $this->smtp->Close();
658 * Sets the language for all class error messages. Returns false
659 * if it cannot load the language file. The default language type
661 * @param string $lang_type Type of language (e.g. Portuguese: "br")
662 * @param string $lang_path Path to the language file directory
666 function SetLanguage($lang_type = 'en', $lang_path = 'language/') {
667 if( !(@include $lang_path.'phpmailer.lang-'.$lang_type.'.php') ) {
668 $PHPMAILER_LANG = array();
669 $PHPMAILER_LANG["provide_address"] = 'You must provide at least one ' .
670 $PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.';
671 $PHPMAILER_LANG["execute"] = 'Could not execute: ';
672 $PHPMAILER_LANG["instantiate"] = 'Could not instantiate mail function.';
673 $PHPMAILER_LANG["authenticate"] = 'SMTP Error: Could not authenticate.';
674 $PHPMAILER_LANG["from_failed"] = 'The following From address failed: ';
675 $PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: The following ' .
676 $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data not accepted.';
677 $PHPMAILER_LANG["connect_host"] = 'SMTP Error: Could not connect to SMTP host.';
678 $PHPMAILER_LANG["file_access"] = 'Could not access file: ';
679 $PHPMAILER_LANG["file_open"] = 'File Error: Could not open file: ';
680 $PHPMAILER_LANG["encoding"] = 'Unknown encoding: ';
681 $PHPMAILER_LANG["signing"] = 'Signing Error: ';
683 $this->language = $PHPMAILER_LANG;
687 /////////////////////////////////////////////////
688 // METHODS, MESSAGE CREATION
689 /////////////////////////////////////////////////
692 * Creates recipient headers.
696 public function AddrAppend($type, $addr) {
697 $addr_str = $type . ': ';
698 $addr_str .= $this->AddrFormat($addr[0]);
699 if(count($addr) > 1) {
700 for($i = 1; $i < count($addr); $i++) {
701 $addr_str .= ', ' . $this->AddrFormat($addr[$i]);
704 $addr_str .= $this->LE;
710 * Formats an address correctly.
714 public function AddrFormat($addr) {
715 if(empty($addr[1])) {
716 $formatted = $this->SecureHeader($addr[0]);
718 $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
725 * Wraps message for use with mailers that do not
726 * automatically perform wrapping and for quoted-printable.
727 * Original written by philippe.
731 public function WrapText($message, $length, $qp_mode = false) {
732 $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
733 // If utf-8 encoding is used, we will need to make sure we don't
734 // split multibyte characters when we wrap
735 $is_utf8 = (strtolower($this->CharSet) == "utf-8");
737 $message = $this->FixEOL($message);
738 if (substr($message, -1) == $this->LE) {
739 $message = substr($message, 0, -1);
742 $line = explode($this->LE, $message);
744 for ($i=0 ;$i < count($line); $i++) {
745 $line_part = explode(' ', $line[$i]);
747 for ($e = 0; $e<count($line_part); $e++) {
748 $word = $line_part[$e];
749 if ($qp_mode and (strlen($word) > $length)) {
750 $space_left = $length - strlen($buf) - 1;
752 if ($space_left > 20) {
755 $len = $this->UTF8CharBoundary($word, $len);
756 } elseif (substr($word, $len - 1, 1) == "=") {
758 } elseif (substr($word, $len - 2, 1) == "=") {
761 $part = substr($word, 0, $len);
762 $word = substr($word, $len);
764 $message .= $buf . sprintf("=%s", $this->LE);
766 $message .= $buf . $soft_break;
770 while (strlen($word) > 0) {
773 $len = $this->UTF8CharBoundary($word, $len);
774 } elseif (substr($word, $len - 1, 1) == "=") {
776 } elseif (substr($word, $len - 2, 1) == "=") {
779 $part = substr($word, 0, $len);
780 $word = substr($word, $len);
782 if (strlen($word) > 0) {
783 $message .= $part . sprintf("=%s", $this->LE);
790 $buf .= ($e == 0) ? $word : (' ' . $word);
792 if (strlen($buf) > $length and $buf_o != '') {
793 $message .= $buf_o . $soft_break;
798 $message .= $buf . $this->LE;
805 * Finds last character boundary prior to maxLength in a utf-8
806 * quoted (printable) encoded string.
807 * Original written by Colin Brown.
809 * @param string $encodedText utf-8 QP text
810 * @param int $maxLength find last character boundary prior to this length
813 public function UTF8CharBoundary($encodedText, $maxLength) {
814 $foundSplitPos = false;
816 while (!$foundSplitPos) {
817 $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
818 $encodedCharPos = strpos($lastChunk, "=");
819 if ($encodedCharPos !== false) {
820 // Found start of encoded character byte within $lookBack block.
821 // Check the encoded byte value (the 2 chars after the '=')
822 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
824 if ($dec < 128) { // Single byte character.
825 // If the encoded char was found at pos 0, it will fit
826 // otherwise reduce maxLength to start of the encoded char
827 $maxLength = ($encodedCharPos == 0) ? $maxLength :
828 $maxLength - ($lookBack - $encodedCharPos);
829 $foundSplitPos = true;
830 } elseif ($dec >= 192) { // First byte of a multi byte character
831 // Reduce maxLength to split at start of character
832 $maxLength = $maxLength - ($lookBack - $encodedCharPos);
833 $foundSplitPos = true;
834 } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
838 // No encoded character found
839 $foundSplitPos = true;
847 * Set the body wrapping.
851 public function SetWordWrap() {
852 if($this->WordWrap < 1) {
856 switch($this->message_type) {
859 case 'alt_attachments':
860 $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
863 $this->Body = $this->WrapText($this->Body, $this->WordWrap);
869 * Assembles message header.
873 public function CreateHeader() {
876 /* Set the boundaries */
877 $uniq_id = md5(uniqid(time()));
878 $this->boundary[1] = 'b1_' . $uniq_id;
879 $this->boundary[2] = 'b2_' . $uniq_id;
881 $result .= $this->HeaderLine('Date', $this->RFCDate());
882 if($this->Sender == '') {
883 $result .= $this->HeaderLine('Return-Path', trim($this->From));
885 $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
888 /* To be created automatically by mail() */
889 if($this->Mailer != 'mail') {
890 if(count($this->to) > 0) {
891 $result .= $this->AddrAppend('To', $this->to);
892 } elseif (count($this->cc) == 0) {
893 $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
898 $from[0][0] = trim($this->From);
899 $from[0][1] = $this->FromName;
900 $result .= $this->AddrAppend('From', $from);
902 /* sendmail and mail() extract Cc from the header before sending */
903 if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
904 $result .= $this->AddrAppend('Cc', $this->cc);
907 /* sendmail and mail() extract Bcc from the header before sending */
908 if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
909 $result .= $this->AddrAppend('Bcc', $this->bcc);
912 if(count($this->ReplyTo) > 0) {
913 $result .= $this->AddrAppend('Reply-to', $this->ReplyTo);
916 /* mail() sets the subject itself */
917 if($this->Mailer != 'mail') {
918 $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
921 if($this->MessageID != '') {
922 $result .= $this->HeaderLine('Message-ID',$this->MessageID);
924 $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
926 $result .= $this->HeaderLine('X-Priority', $this->Priority);
927 $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.codeworxtech.com) [version ' . $this->Version . ']');
929 if($this->ConfirmReadingTo != '') {
930 $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
933 // Add custom headers
934 for($index = 0; $index < count($this->CustomHeader); $index++) {
935 $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
937 if (!$this->sign_key_file) {
938 $result .= $this->HeaderLine('MIME-Version', '1.0');
939 $result .= $this->GetMailMIME();
946 * Returns the message MIME.
950 public function GetMailMIME() {
952 switch($this->message_type) {
954 $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
955 $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
959 case 'alt_attachments':
960 if($this->InlineImageExists()){
961 $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
963 $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
964 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
968 $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
969 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
973 if($this->Mailer != 'mail') {
974 $result .= $this->LE.$this->LE;
981 * Assembles the message body. Returns an empty string on failure.
985 public function CreateBody() {
988 if ($this->sign_key_file) {
989 $result .= $this->GetMailMIME();
992 $this->SetWordWrap();
994 switch($this->message_type) {
996 $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
997 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
998 $result .= $this->LE.$this->LE;
999 $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
1000 $result .= $this->EncodeString($this->Body, $this->Encoding);
1001 $result .= $this->LE.$this->LE;
1002 $result .= $this->EndBoundary($this->boundary[1]);
1005 $result .= $this->EncodeString($this->Body, $this->Encoding);
1008 $result .= $this->GetBoundary($this->boundary[1], '', '', '');
1009 $result .= $this->EncodeString($this->Body, $this->Encoding);
1010 $result .= $this->LE;
1011 $result .= $this->AttachAll();
1013 case 'alt_attachments':
1014 $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
1015 $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
1016 $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
1017 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
1018 $result .= $this->LE.$this->LE;
1019 $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
1020 $result .= $this->EncodeString($this->Body, $this->Encoding);
1021 $result .= $this->LE.$this->LE;
1022 $result .= $this->EndBoundary($this->boundary[2]);
1023 $result .= $this->AttachAll();
1027 if($this->IsError()) {
1029 } else if ($this->sign_key_file) {
1030 $file = tempnam("", "mail");
1031 $fp = fopen($file, "w");
1032 fwrite($fp, $result);
1034 $signed = tempnam("", "signed");
1036 if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), null)) {
1037 $fp = fopen($signed, "r");
1040 $result = $result . fread($fp, 1024);
1044 $this->SetError($this->Lang("signing").openssl_error_string());
1056 * Returns the start of a message boundary.
1059 public function GetBoundary($boundary, $charSet, $contentType, $encoding) {
1061 if($charSet == '') {
1062 $charSet = $this->CharSet;
1064 if($contentType == '') {
1065 $contentType = $this->ContentType;
1067 if($encoding == '') {
1068 $encoding = $this->Encoding;
1070 $result .= $this->TextLine('--' . $boundary);
1071 $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
1072 $result .= $this->LE;
1073 $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
1074 $result .= $this->LE;
1080 * Returns the end of a message boundary.
1083 public function EndBoundary($boundary) {
1084 return $this->LE . '--' . $boundary . '--' . $this->LE;
1088 * Sets the message type.
1092 public function SetMessageType() {
1093 if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
1094 $this->message_type = 'plain';
1096 if(count($this->attachment) > 0) {
1097 $this->message_type = 'attachments';
1099 if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
1100 $this->message_type = 'alt';
1102 if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
1103 $this->message_type = 'alt_attachments';
1108 /* Returns a formatted header line.
1112 public function HeaderLine($name, $value) {
1113 return $name . ': ' . $value . $this->LE;
1117 * Returns a formatted mail line.
1121 public function TextLine($value) {
1122 return $value . $this->LE;
1125 /////////////////////////////////////////////////
1126 // CLASS METHODS, ATTACHMENTS
1127 /////////////////////////////////////////////////
1130 * Adds an attachment from a path on the filesystem.
1131 * Returns false if the file could not be found
1133 * @param string $path Path to the attachment.
1134 * @param string $name Overrides the attachment name.
1135 * @param string $encoding File encoding (see $Encoding).
1136 * @param string $type File extension (MIME) type.
1139 public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
1140 if(!@is_file($path)) {
1141 $this->SetError($this->Lang('file_access') . $path);
1145 $filename = basename($path);
1150 $cur = count($this->attachment);
1151 $this->attachment[$cur][0] = $path;
1152 $this->attachment[$cur][1] = $filename;
1153 $this->attachment[$cur][2] = $name;
1154 $this->attachment[$cur][3] = $encoding;
1155 $this->attachment[$cur][4] = $type;
1156 $this->attachment[$cur][5] = false; // isStringAttachment
1157 $this->attachment[$cur][6] = 'attachment';
1158 $this->attachment[$cur][7] = 0;
1164 * Attaches all fs, string, and binary attachments to the message.
1165 * Returns an empty string on failure.
1169 public function AttachAll() {
1170 /* Return text of body */
1173 /* Add all attachments */
1174 for($i = 0; $i < count($this->attachment); $i++) {
1175 /* Check for string attachment */
1176 $bString = $this->attachment[$i][5];
1178 $string = $this->attachment[$i][0];
1180 $path = $this->attachment[$i][0];
1183 $filename = $this->attachment[$i][1];
1184 $name = $this->attachment[$i][2];
1185 $encoding = $this->attachment[$i][3];
1186 $type = $this->attachment[$i][4];
1187 $disposition = $this->attachment[$i][6];
1188 $cid = $this->attachment[$i][7];
1190 $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
1191 //$mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
1192 $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
1193 $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
1195 if($disposition == 'inline') {
1196 $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
1199 //$mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $name, $this->LE.$this->LE);
1200 $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
1202 /* Encode as string attachment */
1204 $mime[] = $this->EncodeString($string, $encoding);
1205 if($this->IsError()) {
1208 $mime[] = $this->LE.$this->LE;
1210 $mime[] = $this->EncodeFile($path, $encoding);
1211 if($this->IsError()) {
1214 $mime[] = $this->LE.$this->LE;
1218 $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
1220 return join('', $mime);
1224 * Encodes attachment in requested format. Returns an
1225 * empty string on failure.
1229 public function EncodeFile ($path, $encoding = 'base64') {
1230 if(!@$fd = fopen($path, 'rb')) {
1231 $this->SetError($this->Lang('file_open') . $path);
1234 if (function_exists('get_magic_quotes')) {
1235 function get_magic_quotes() {
1239 if (PHP_VERSION < 6) {
1240 $magic_quotes = get_magic_quotes_runtime();
1241 set_magic_quotes_runtime(0);
1243 $file_buffer = file_get_contents($path);
1244 $file_buffer = $this->EncodeString($file_buffer, $encoding);
1246 if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); }
1247 return $file_buffer;
1251 * Encodes string to requested format. Returns an
1252 * empty string on failure.
1256 public function EncodeString ($str, $encoding = 'base64') {
1258 switch(strtolower($encoding)) {
1260 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
1264 $encoded = $this->FixEOL($str);
1265 if (substr($encoded, -(strlen($this->LE))) != $this->LE)
1266 $encoded .= $this->LE;
1271 case 'quoted-printable':
1272 $encoded = $this->EncodeQP($str);
1275 $this->SetError($this->Lang('encoding') . $encoding);
1282 * Encode a header string to best of Q, B, quoted or none.
1286 public function EncodeHeader ($str, $position = 'text') {
1289 switch (strtolower($position)) {
1291 if (!preg_match('/[\200-\377]/', $str)) {
1292 /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */
1293 $encoded = addcslashes($str, "\0..\37\177\\\"");
1294 if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
1297 return ("\"$encoded\"");
1300 $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
1303 $x = preg_match_all('/[()"]/', $str, $matches);
1307 $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
1315 $maxlen = 75 - 7 - strlen($this->CharSet);
1316 /* Try to select the encoding which should produce the shortest output */
1317 if (strlen($str)/3 < $x) {
1319 if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
1320 // Use a custom function which correctly encodes and wraps long
1321 // multibyte strings without breaking lines within a character
1322 $encoded = $this->Base64EncodeWrapMB($str);
1324 $encoded = base64_encode($str);
1325 $maxlen -= $maxlen % 4;
1326 $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
1330 $encoded = $this->EncodeQ($str, $position);
1331 $encoded = $this->WrapText($encoded, $maxlen, true);
1332 $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
1335 $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
1336 $encoded = trim(str_replace("\n", $this->LE, $encoded));
1342 * Checks if a string contains multibyte characters.
1344 * @param string $str multi-byte text to wrap encode
1347 public function HasMultiBytes($str) {
1348 if (function_exists('mb_strlen')) {
1349 return (strlen($str) > mb_strlen($str, $this->CharSet));
1350 } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
1356 * Correctly encodes and wraps long multibyte strings for mail headers
1357 * without breaking lines within a character.
1358 * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
1360 * @param string $str multi-byte text to wrap encode
1363 public function Base64EncodeWrapMB($str) {
1364 $start = "=?".$this->CharSet."?B?";
1368 $mb_length = mb_strlen($str, $this->CharSet);
1369 // Each line must have length <= 75, including $start and $end
1370 $length = 75 - strlen($start) - strlen($end);
1371 // Average multi-byte ratio
1372 $ratio = $mb_length / strlen($str);
1373 // Base64 has a 4:3 ratio
1374 $offset = $avgLength = floor($length * $ratio * .75);
1376 for ($i = 0; $i < $mb_length; $i += $offset) {
1380 $offset = $avgLength - $lookBack;
1381 $chunk = mb_substr($str, $i, $offset, $this->CharSet);
1382 $chunk = base64_encode($chunk);
1385 while (strlen($chunk) > $length);
1387 $encoded .= $chunk . $this->LE;
1390 // Chomp the last linefeed
1391 $encoded = substr($encoded, 0, -strlen($this->LE));
1396 * Encode string to quoted-printable.
1398 * @param string $string the text to encode
1399 * @param integer $line_max Number of chars allowed on a line before wrapping
1402 public function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) {
1403 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
1404 $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
1408 while( list(, $line) = each($lines) ) {
1409 $linlen = strlen($line);
1411 for($i = 0; $i < $linlen; $i++) {
1412 $c = substr( $line, $i, 1 );
1414 if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
1418 if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
1420 } else if ( $space_conv ) {
1423 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
1424 $h2 = floor($dec/16);
1425 $h1 = floor($dec%16);
1426 $c = $escape.$hex[$h2].$hex[$h1];
1428 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
1429 $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
1431 // check if newline first character will be point or not
1438 $output .= $newline.$eol;
1444 * Encode string to q encoding.
1448 public function EncodeQ ($str, $position = 'text') {
1449 /* There should not be any EOL in the string */
1450 $encoded = preg_replace("[\r\n]", '', $str);
1452 switch (strtolower($position)) {
1454 $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
1457 $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
1460 /* Replace every high ascii, control =, ? and _ characters */
1461 $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
1462 "'='.sprintf('%02X', ord('\\1'))", $encoded);
1466 /* Replace every spaces to _ (more readable than =20) */
1467 $encoded = str_replace(' ', '_', $encoded);
1473 * Adds a string or binary attachment (non-filesystem) to the list.
1474 * This method can be used to attach ascii or binary data,
1475 * such as a BLOB record from a database.
1476 * @param string $string String attachment data.
1477 * @param string $filename Name of the attachment.
1478 * @param string $encoding File encoding (see $Encoding).
1479 * @param string $type File extension (MIME) type.
1482 public function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
1483 /* Append to $attachment array */
1484 $cur = count($this->attachment);
1485 $this->attachment[$cur][0] = $string;
1486 $this->attachment[$cur][1] = $filename;
1487 $this->attachment[$cur][2] = $filename;
1488 $this->attachment[$cur][3] = $encoding;
1489 $this->attachment[$cur][4] = $type;
1490 $this->attachment[$cur][5] = true; // isString
1491 $this->attachment[$cur][6] = 'attachment';
1492 $this->attachment[$cur][7] = 0;
1496 * Adds an embedded attachment. This can include images, sounds, and
1497 * just about any other document. Make sure to set the $type to an
1498 * image type. For JPEG images use "image/jpeg" and for GIF images
1500 * @param string $path Path to the attachment.
1501 * @param string $cid Content ID of the attachment. Use this to identify
1502 * the Id for accessing the image in an HTML form.
1503 * @param string $name Overrides the attachment name.
1504 * @param string $encoding File encoding (see $Encoding).
1505 * @param string $type File extension (MIME) type.
1508 public function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
1510 if(!@is_file($path)) {
1511 $this->SetError($this->Lang('file_access') . $path);
1515 $filename = basename($path);
1520 /* Append to $attachment array */
1521 $cur = count($this->attachment);
1522 $this->attachment[$cur][0] = $path;
1523 $this->attachment[$cur][1] = $filename;
1524 $this->attachment[$cur][2] = $name;
1525 $this->attachment[$cur][3] = $encoding;
1526 $this->attachment[$cur][4] = $type;
1527 $this->attachment[$cur][5] = false;
1528 $this->attachment[$cur][6] = 'inline';
1529 $this->attachment[$cur][7] = $cid;
1535 * Returns true if an inline attachment is present.
1539 public function InlineImageExists() {
1541 for($i = 0; $i < count($this->attachment); $i++) {
1542 if($this->attachment[$i][6] == 'inline') {
1551 /////////////////////////////////////////////////
1552 // CLASS METHODS, MESSAGE RESET
1553 /////////////////////////////////////////////////
1556 * Clears all recipients assigned in the TO array. Returns void.
1559 public function ClearAddresses() {
1560 $this->to = array();
1564 * Clears all recipients assigned in the CC array. Returns void.
1567 public function ClearCCs() {
1568 $this->cc = array();
1572 * Clears all recipients assigned in the BCC array. Returns void.
1575 public function ClearBCCs() {
1576 $this->bcc = array();
1580 * Clears all recipients assigned in the ReplyTo array. Returns void.
1583 public function ClearReplyTos() {
1584 $this->ReplyTo = array();
1588 * Clears all recipients assigned in the TO, CC and BCC
1589 * array. Returns void.
1592 public function ClearAllRecipients() {
1593 $this->to = array();
1594 $this->cc = array();
1595 $this->bcc = array();
1599 * Clears all previously set filesystem, string, and binary
1600 * attachments. Returns void.
1603 public function ClearAttachments() {
1604 $this->attachment = array();
1608 * Clears all custom headers. Returns void.
1611 public function ClearCustomHeaders() {
1612 $this->CustomHeader = array();
1615 /////////////////////////////////////////////////
1616 // CLASS METHODS, MISCELLANEOUS
1617 /////////////////////////////////////////////////
1620 * Adds the error message to the error container.
1625 private function SetError($msg) {
1626 $this->error_count++;
1627 $this->ErrorInfo = $msg;
1631 * Returns the proper RFC 822 formatted date.
1635 private static function RFCDate() {
1637 $tzs = ($tz < 0) ? '-' : '+';
1639 $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
1640 $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
1646 * Returns the server hostname or 'localhost.localdomain' if unknown.
1650 private function ServerHostname() {
1651 if (!empty($this->Hostname)) {
1652 $result = $this->Hostname;
1653 } elseif (isset($_SERVER['SERVER_NAME'])) {
1654 $result = $_SERVER['SERVER_NAME'];
1656 $result = "localhost.localdomain";
1663 * Returns a message in the appropriate language.
1667 private function Lang($key) {
1668 if(count($this->language) < 1) {
1669 $this->SetLanguage('en'); // set the default language
1672 if(isset($this->language[$key])) {
1673 return $this->language[$key];
1675 return 'Language string failed to load: ' . $key;
1680 * Returns true if an error occurred.
1684 public function IsError() {
1685 return ($this->error_count > 0);
1689 * Changes every end of line from CR or LF to CRLF.
1693 private function FixEOL($str) {
1694 $str = str_replace("\r\n", "\n", $str);
1695 $str = str_replace("\r", "\n", $str);
1696 $str = str_replace("\n", $this->LE, $str);
1701 * Adds a custom header.
1705 public function AddCustomHeader($custom_header) {
1706 $this->CustomHeader[] = explode(':', $custom_header, 2);
1710 * Evaluates the message and returns modifications for inline images and backgrounds
1714 public function MsgHTML($message,$basedir='') {
1715 preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
1716 if(isset($images[2])) {
1717 foreach($images[2] as $i => $url) {
1718 // do not change urls for absolute images (thanks to corvuscorax)
1719 if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) {
1720 $filename = basename($url);
1721 $directory = dirname($url);
1722 ($directory == '.')?$directory='':'';
1723 $cid = 'cid:' . md5($filename);
1724 $fileParts = split("\.", $filename);
1725 $ext = $fileParts[1];
1726 $mimeType = $this->_mime_types($ext);
1727 if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
1728 if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
1729 if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
1730 $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
1735 $this->IsHTML(true);
1736 $this->Body = $message;
1737 $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
1738 if ( !empty($textMsg) && empty($this->AltBody) ) {
1739 $this->AltBody = html_entity_decode($textMsg);
1741 if ( empty($this->AltBody) ) {
1742 $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";
1747 * Gets the mime type of the embedded or inline image
1749 * @return mime type of ext
1751 public function _mime_types($ext = '') {
1753 'hqx' => 'application/mac-binhex40',
1754 'cpt' => 'application/mac-compactpro',
1755 'doc' => 'application/msword',
1756 'bin' => 'application/macbinary',
1757 'dms' => 'application/octet-stream',
1758 'lha' => 'application/octet-stream',
1759 'lzh' => 'application/octet-stream',
1760 'exe' => 'application/octet-stream',
1761 'class' => 'application/octet-stream',
1762 'psd' => 'application/octet-stream',
1763 'so' => 'application/octet-stream',
1764 'sea' => 'application/octet-stream',
1765 'dll' => 'application/octet-stream',
1766 'oda' => 'application/oda',
1767 'pdf' => 'application/pdf',
1768 'ai' => 'application/postscript',
1769 'eps' => 'application/postscript',
1770 'ps' => 'application/postscript',
1771 'smi' => 'application/smil',
1772 'smil' => 'application/smil',
1773 'mif' => 'application/vnd.mif',
1774 'xls' => 'application/vnd.ms-excel',
1775 'ppt' => 'application/vnd.ms-powerpoint',
1776 'wbxml' => 'application/vnd.wap.wbxml',
1777 'wmlc' => 'application/vnd.wap.wmlc',
1778 'dcr' => 'application/x-director',
1779 'dir' => 'application/x-director',
1780 'dxr' => 'application/x-director',
1781 'dvi' => 'application/x-dvi',
1782 'gtar' => 'application/x-gtar',
1783 'php' => 'application/x-httpd-php',
1784 'php4' => 'application/x-httpd-php',
1785 'php3' => 'application/x-httpd-php',
1786 'phtml' => 'application/x-httpd-php',
1787 'phps' => 'application/x-httpd-php-source',
1788 'js' => 'application/x-javascript',
1789 'swf' => 'application/x-shockwave-flash',
1790 'sit' => 'application/x-stuffit',
1791 'tar' => 'application/x-tar',
1792 'tgz' => 'application/x-tar',
1793 'xhtml' => 'application/xhtml+xml',
1794 'xht' => 'application/xhtml+xml',
1795 'zip' => 'application/zip',
1796 'mid' => 'audio/midi',
1797 'midi' => 'audio/midi',
1798 'mpga' => 'audio/mpeg',
1799 'mp2' => 'audio/mpeg',
1800 'mp3' => 'audio/mpeg',
1801 'aif' => 'audio/x-aiff',
1802 'aiff' => 'audio/x-aiff',
1803 'aifc' => 'audio/x-aiff',
1804 'ram' => 'audio/x-pn-realaudio',
1805 'rm' => 'audio/x-pn-realaudio',
1806 'rpm' => 'audio/x-pn-realaudio-plugin',
1807 'ra' => 'audio/x-realaudio',
1808 'rv' => 'video/vnd.rn-realvideo',
1809 'wav' => 'audio/x-wav',
1810 'bmp' => 'image/bmp',
1811 'gif' => 'image/gif',
1812 'jpeg' => 'image/jpeg',
1813 'jpg' => 'image/jpeg',
1814 'jpe' => 'image/jpeg',
1815 'png' => 'image/png',
1816 'tiff' => 'image/tiff',
1817 'tif' => 'image/tiff',
1818 'css' => 'text/css',
1819 'html' => 'text/html',
1820 'htm' => 'text/html',
1821 'shtml' => 'text/html',
1822 'txt' => 'text/plain',
1823 'text' => 'text/plain',
1824 'log' => 'text/plain',
1825 'rtx' => 'text/richtext',
1826 'rtf' => 'text/rtf',
1827 'xml' => 'text/xml',
1828 'xsl' => 'text/xml',
1829 'mpeg' => 'video/mpeg',
1830 'mpg' => 'video/mpeg',
1831 'mpe' => 'video/mpeg',
1832 'qt' => 'video/quicktime',
1833 'mov' => 'video/quicktime',
1834 'avi' => 'video/x-msvideo',
1835 'movie' => 'video/x-sgi-movie',
1836 'doc' => 'application/msword',
1837 'word' => 'application/msword',
1838 'xl' => 'application/excel',
1839 'eml' => 'message/rfc822'
1841 return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
1845 * Set (or reset) Class Objects (variables)
1848 * $page->set('X-Priority', '3');
1851 * @param string $name Parameter Name
1852 * @param mixed $value Parameter Value
1853 * NOTE: will not work with arrays, there are no arrays to set/reset
1855 public function set ( $name, $value = '' ) {
1856 if ( isset($this->$name) ) {
1857 $this->$name = $value;
1859 $this->SetError('Cannot set or reset variable ' . $name);
1865 * Read a file from a supplied filename and return it.
1868 * @param string $filename Parameter File Name
1870 public function getFile($filename) {
1872 if ($fp = fopen($filename, 'rb')) {
1873 while (!feof($fp)) {
1874 $return .= fread($fp, 1024);
1884 * Strips newlines to prevent header injection.
1886 * @param string $str String
1889 public function SecureHeader($str) {
1891 $str = str_replace("\r", "", $str);
1892 $str = str_replace("\n", "", $str);
1897 * Set the private key file and password to sign the message.
1900 * @param string $key_filename Parameter File Name
1901 * @param string $key_pass Password for private key
1903 public function Sign($cert_filename, $key_filename, $key_pass) {
1904 $this->sign_cert_file = $cert_filename;
1905 $this->sign_key_file = $key_filename;
1906 $this->sign_key_pass = $key_pass;