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
30 * @author Andy Prevost
31 * @copyright 2004 - 2008 Andy Prevost
36 /////////////////////////////////////////////////
38 /////////////////////////////////////////////////
41 * Email priority (1 = High, 3 = Normal, 5 = low).
47 * Sets the CharSet of the message.
50 var $CharSet = 'iso-8859-1';
53 * Sets the Content-type of the message.
56 var $ContentType = 'text/plain';
59 * Sets the Encoding of the message. Options for this are "8bit",
60 * "7bit", "binary", "base64", and "quoted-printable".
63 var $Encoding = '8bit';
66 * Holds the most recent mailer error message.
72 * Sets the From email address for the message.
75 var $From = 'root@localhost';
78 * Sets the From name of the message.
81 var $FromName = 'Root User';
84 * Sets the Sender email (Return-Path) of the message. If not empty,
85 * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
91 * Sets the Subject of the message.
97 * Sets the Body of the message. This can be either an HTML or text body.
98 * If HTML then run IsHTML(true).
104 * Sets the text-only body of the message. This automatically sets the
105 * email to multipart/alternative. This body can be read by mail
106 * clients that do not have HTML email capability such as mutt. Clients
107 * that can read HTML will view the normal Body.
113 * Sets word wrapping on the body of the message to a given number of
120 * Method to send mail: ("mail", "sendmail", or "smtp").
123 var $Mailer = 'mail';
126 * Sets the path of the sendmail program.
129 var $Sendmail = '/usr/sbin/sendmail';
132 * Path to PHPMailer plugins. This is now only useful if the SMTP class
133 * is in a different directory than the PHP include path.
139 * Holds PHPMailer version.
142 var $Version = "2.0.3";
145 * Sets the email address that a reading confirmation will be sent.
148 var $ConfirmReadingTo = '';
151 * Sets the hostname to use in Message-Id and Received headers
152 * and as default HELO string. If empty, the value returned
153 * by SERVER_NAME is used or 'localhost.localdomain'.
159 * Sets the message id to be used in the Message-Id header.
160 * If empty, a unique id will be generated.
165 /////////////////////////////////////////////////
166 // PROPERTIES FOR SMTP
167 /////////////////////////////////////////////////
170 * Sets the SMTP hosts. All hosts must be separated by a
171 * semicolon. You can also specify a different port
172 * for each host by using this format: [hostname:port]
173 * (e.g. "smtp1.example.com:25;smtp2.example.com").
174 * Hosts will be tried in order.
177 var $Host = 'localhost';
180 * Sets the default SMTP server port.
186 * Sets the SMTP HELO of the message (Default is $Hostname).
192 * Sets connection prefix.
193 * Options are "", "ssl" or "tls"
196 var $SMTPSecure = "";
199 * Sets SMTP authentication. Utilizes the Username and Password variables.
202 var $SMTPAuth = false;
205 * Sets SMTP username.
211 * Sets SMTP password.
217 * Sets the SMTP server timeout in seconds. This function will not
218 * work with the win32 version.
224 * Sets SMTP class debugging on or off.
227 var $SMTPDebug = false;
230 * Prevents the SMTP connection from being closed after each mail
231 * sending. If this is set to true then to close the connection
232 * requires an explicit call to SmtpClose().
235 var $SMTPKeepAlive = false;
238 * Provides the ability to have the TO field process individual
239 * emails, instead of sending to entire TO addresses
242 var $SingleTo = false;
244 /////////////////////////////////////////////////
245 // PROPERTIES, PRIVATE
246 /////////////////////////////////////////////////
252 var $ReplyTo = array();
253 var $attachment = array();
254 var $CustomHeader = array();
255 var $message_type = '';
256 var $boundary = array();
257 var $language = array();
258 var $error_count = 0;
260 var $sign_cert_file = "";
261 var $sign_key_file = "";
262 var $sign_key_pass = "";
264 /////////////////////////////////////////////////
265 // METHODS, VARIABLES
266 /////////////////////////////////////////////////
269 * Sets message type to HTML.
273 function IsHTML($bool) {
275 $this->ContentType = 'text/html';
277 $this->ContentType = 'text/plain';
282 * Sets Mailer to send message using SMTP.
286 $this->Mailer = 'smtp';
290 * Sets Mailer to send message using PHP mail() function.
294 $this->Mailer = 'mail';
298 * Sets Mailer to send message using the $Sendmail program.
301 function IsSendmail() {
302 $this->Mailer = 'sendmail';
306 * Sets Mailer to send message using the qmail MTA.
310 $this->Sendmail = '/var/qmail/bin/sendmail';
311 $this->Mailer = 'sendmail';
314 /////////////////////////////////////////////////
315 // METHODS, RECIPIENTS
316 /////////////////////////////////////////////////
319 * Adds a "To" address.
320 * @param string $address
321 * @param string $name
324 function AddAddress($address, $name = '') {
325 $cur = count($this->to);
326 $this->to[$cur][0] = trim($address);
327 $this->to[$cur][1] = $name;
331 * Adds a "Cc" address. Note: this function works
332 * with the SMTP mailer on win32, not with the "mail"
334 * @param string $address
335 * @param string $name
338 function AddCC($address, $name = '') {
339 $cur = count($this->cc);
340 $this->cc[$cur][0] = trim($address);
341 $this->cc[$cur][1] = $name;
345 * Adds a "Bcc" address. Note: this function works
346 * with the SMTP mailer on win32, not with the "mail"
348 * @param string $address
349 * @param string $name
352 function AddBCC($address, $name = '') {
353 $cur = count($this->bcc);
354 $this->bcc[$cur][0] = trim($address);
355 $this->bcc[$cur][1] = $name;
359 * Adds a "Reply-To" address.
360 * @param string $address
361 * @param string $name
364 function AddReplyTo($address, $name = '') {
365 $cur = count($this->ReplyTo);
366 $this->ReplyTo[$cur][0] = trim($address);
367 $this->ReplyTo[$cur][1] = $name;
370 /////////////////////////////////////////////////
371 // METHODS, MAIL SENDING
372 /////////////////////////////////////////////////
375 * Creates message and assigns Mailer. If the message is
376 * not sent successfully then it returns false. Use the ErrorInfo
377 * variable to view description of the error.
385 if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
386 $this->SetError($this->Lang('provide_address'));
390 /* Set whether the message is multipart/alternative */
391 if(!empty($this->AltBody)) {
392 $this->ContentType = 'multipart/alternative';
395 $this->error_count = 0; // reset errors
396 $this->SetMessageType();
397 $header .= $this->CreateHeader();
398 $body = $this->CreateBody();
404 /* Choose the mailer */
405 switch($this->Mailer) {
407 $result = $this->SendmailSend($header, $body);
410 $result = $this->SmtpSend($header, $body);
413 $result = $this->MailSend($header, $body);
416 $result = $this->MailSend($header, $body);
418 //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
427 * Sends mail using the $Sendmail program.
431 function SendmailSend($header, $body) {
432 if ($this->Sender != '') {
433 $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
435 $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
438 if(!@$mail = popen($sendmail, 'w')) {
439 $this->SetError($this->Lang('execute') . $this->Sendmail);
443 fputs($mail, $header);
446 $result = pclose($mail);
447 if (version_compare(phpversion(), '4.2.3') == -1) {
448 $result = $result >> 8 & 0xFF;
451 $this->SetError($this->Lang('execute') . $this->Sendmail);
458 * Sends mail using the PHP mail() function.
462 function MailSend($header, $body) {
465 for($i = 0; $i < count($this->to); $i++) {
466 if($i != 0) { $to .= ', '; }
467 $to .= $this->AddrFormat($this->to[$i]);
470 $toArr = split(',', $to);
472 $params = sprintf("-oi -f %s", $this->Sender);
473 if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) {
474 $old_from = ini_get('sendmail_from');
475 ini_set('sendmail_from', $this->Sender);
476 if ($this->SingleTo === true && count($toArr) > 1) {
477 foreach ($toArr as $key => $val) {
478 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
481 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
484 if ($this->SingleTo === true && count($toArr) > 1) {
485 foreach ($toArr as $key => $val) {
486 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
489 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
493 if (isset($old_from)) {
494 ini_set('sendmail_from', $old_from);
498 $this->SetError($this->Lang('instantiate'));
506 * Sends mail via SMTP using PhpSMTP (Author:
507 * Chris Ryan). Returns bool. Returns false if there is a
508 * bad MAIL FROM, RCPT, or DATA input.
512 function SmtpSend($header, $body) {
513 include_once($this->PluginDir . 'class.smtp.php');
517 if(!$this->SmtpConnect()) {
521 $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
522 if(!$this->smtp->Mail($smtp_from)) {
523 $error = $this->Lang('from_failed') . $smtp_from;
524 $this->SetError($error);
525 $this->smtp->Reset();
529 /* Attempt to send attach all recipients */
530 for($i = 0; $i < count($this->to); $i++) {
531 if(!$this->smtp->Recipient($this->to[$i][0])) {
532 $bad_rcpt[] = $this->to[$i][0];
535 for($i = 0; $i < count($this->cc); $i++) {
536 if(!$this->smtp->Recipient($this->cc[$i][0])) {
537 $bad_rcpt[] = $this->cc[$i][0];
540 for($i = 0; $i < count($this->bcc); $i++) {
541 if(!$this->smtp->Recipient($this->bcc[$i][0])) {
542 $bad_rcpt[] = $this->bcc[$i][0];
546 if(count($bad_rcpt) > 0) { // Create error message
547 for($i = 0; $i < count($bad_rcpt); $i++) {
551 $error .= $bad_rcpt[$i];
553 $error = $this->Lang('recipients_failed') . $error;
554 $this->SetError($error);
555 $this->smtp->Reset();
559 if(!$this->smtp->Data($header . $body)) {
560 $this->SetError($this->Lang('data_not_accepted'));
561 $this->smtp->Reset();
564 if($this->SMTPKeepAlive == true) {
565 $this->smtp->Reset();
574 * Initiates a connection to an SMTP server. Returns false if the
579 function SmtpConnect() {
580 if($this->smtp == NULL) {
581 $this->smtp = new SMTP();
584 $this->smtp->do_debug = $this->SMTPDebug;
585 $hosts = explode(';', $this->Host);
587 $connection = ($this->smtp->Connected());
589 /* Retry while there is no connection */
590 while($index < count($hosts) && $connection == false) {
592 if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
593 $host = $hostinfo[1];
594 $port = $hostinfo[2];
596 $host = $hosts[$index];
600 if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) {
601 if ($this->Helo != '') {
602 $this->smtp->Hello($this->Helo);
604 $this->smtp->Hello($this->ServerHostname());
608 if($this->SMTPAuth) {
609 if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
610 $this->SetError($this->Lang('authenticate'));
611 $this->smtp->Reset();
619 $this->SetError($this->Lang('connect_host'));
626 * Closes the active SMTP session if one exists.
629 function SmtpClose() {
630 if($this->smtp != NULL) {
631 if($this->smtp->Connected()) {
633 $this->smtp->Close();
639 * Sets the language for all class error messages. Returns false
640 * if it cannot load the language file. The default language type
642 * @param string $lang_type Type of language (e.g. Portuguese: "br")
643 * @param string $lang_path Path to the language file directory
647 function SetLanguage($lang_type, $lang_path = 'language/') {
648 if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
649 include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
650 } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) {
651 include($lang_path.'phpmailer.lang-en.php');
653 $PHPMAILER_LANG = array();
654 $PHPMAILER_LANG["provide_address"] = 'You must provide at least one ' .
655 $PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.';
656 $PHPMAILER_LANG["execute"] = 'Could not execute: ';
657 $PHPMAILER_LANG["instantiate"] = 'Could not instantiate mail function.';
658 $PHPMAILER_LANG["authenticate"] = 'SMTP Error: Could not authenticate.';
659 $PHPMAILER_LANG["from_failed"] = 'The following From address failed: ';
660 $PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: The following ' .
661 $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data not accepted.';
662 $PHPMAILER_LANG["connect_host"] = 'SMTP Error: Could not connect to SMTP host.';
663 $PHPMAILER_LANG["file_access"] = 'Could not access file: ';
664 $PHPMAILER_LANG["file_open"] = 'File Error: Could not open file: ';
665 $PHPMAILER_LANG["encoding"] = 'Unknown encoding: ';
666 $PHPMAILER_LANG["signing"] = 'Signing Error: ';
668 $this->language = $PHPMAILER_LANG;
673 /////////////////////////////////////////////////
674 // METHODS, MESSAGE CREATION
675 /////////////////////////////////////////////////
678 * Creates recipient headers.
682 function AddrAppend($type, $addr) {
683 $addr_str = $type . ': ';
684 $addr_str .= $this->AddrFormat($addr[0]);
685 if(count($addr) > 1) {
686 for($i = 1; $i < count($addr); $i++) {
687 $addr_str .= ', ' . $this->AddrFormat($addr[$i]);
690 $addr_str .= $this->LE;
696 * Formats an address correctly.
700 function AddrFormat($addr) {
701 if(empty($addr[1])) {
702 $formatted = $this->SecureHeader($addr[0]);
704 $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
711 * Wraps message for use with mailers that do not
712 * automatically perform wrapping and for quoted-printable.
713 * Original written by philippe.
717 function WrapText($message, $length, $qp_mode = false) {
718 $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
719 // If utf-8 encoding is used, we will need to make sure we don't
720 // split multibyte characters when we wrap
721 $is_utf8 = (strtolower($this->CharSet) == "utf-8");
723 $message = $this->FixEOL($message);
724 if (substr($message, -1) == $this->LE) {
725 $message = substr($message, 0, -1);
728 $line = explode($this->LE, $message);
730 for ($i=0 ;$i < count($line); $i++) {
731 $line_part = explode(' ', $line[$i]);
733 for ($e = 0; $e<count($line_part); $e++) {
734 $word = $line_part[$e];
735 if ($qp_mode and (strlen($word) > $length)) {
736 $space_left = $length - strlen($buf) - 1;
738 if ($space_left > 20) {
741 $len = $this->UTF8CharBoundary($word, $len);
742 } elseif (substr($word, $len - 1, 1) == "=") {
744 } elseif (substr($word, $len - 2, 1) == "=") {
747 $part = substr($word, 0, $len);
748 $word = substr($word, $len);
750 $message .= $buf . sprintf("=%s", $this->LE);
752 $message .= $buf . $soft_break;
756 while (strlen($word) > 0) {
759 $len = $this->UTF8CharBoundary($word, $len);
760 } elseif (substr($word, $len - 1, 1) == "=") {
762 } elseif (substr($word, $len - 2, 1) == "=") {
765 $part = substr($word, 0, $len);
766 $word = substr($word, $len);
768 if (strlen($word) > 0) {
769 $message .= $part . sprintf("=%s", $this->LE);
776 $buf .= ($e == 0) ? $word : (' ' . $word);
778 if (strlen($buf) > $length and $buf_o != '') {
779 $message .= $buf_o . $soft_break;
784 $message .= $buf . $this->LE;
791 * Finds last character boundary prior to maxLength in a utf-8
792 * quoted (printable) encoded string.
793 * Original written by Colin Brown.
795 * @param string $encodedText utf-8 QP text
796 * @param int $maxLength find last character boundary prior to this length
799 function UTF8CharBoundary($encodedText, $maxLength) {
800 $foundSplitPos = false;
802 while (!$foundSplitPos) {
803 $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
804 $encodedCharPos = strpos($lastChunk, "=");
805 if ($encodedCharPos !== false) {
806 // Found start of encoded character byte within $lookBack block.
807 // Check the encoded byte value (the 2 chars after the '=')
808 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
810 if ($dec < 128) { // Single byte character.
811 // If the encoded char was found at pos 0, it will fit
812 // otherwise reduce maxLength to start of the encoded char
813 $maxLength = ($encodedCharPos == 0) ? $maxLength :
814 $maxLength - ($lookBack - $encodedCharPos);
815 $foundSplitPos = true;
816 } elseif ($dec >= 192) { // First byte of a multi byte character
817 // Reduce maxLength to split at start of character
818 $maxLength = $maxLength - ($lookBack - $encodedCharPos);
819 $foundSplitPos = true;
820 } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
824 // No encoded character found
825 $foundSplitPos = true;
832 * Set the body wrapping.
836 function SetWordWrap() {
837 if($this->WordWrap < 1) {
841 switch($this->message_type) {
844 case 'alt_attachments':
845 $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
848 $this->Body = $this->WrapText($this->Body, $this->WordWrap);
854 * Assembles message header.
858 function CreateHeader() {
861 /* Set the boundaries */
862 $uniq_id = md5(uniqid(time()));
863 $this->boundary[1] = 'b1_' . $uniq_id;
864 $this->boundary[2] = 'b2_' . $uniq_id;
866 $result .= $this->HeaderLine('Date', $this->RFCDate());
867 if($this->Sender == '') {
868 $result .= $this->HeaderLine('Return-Path', trim($this->From));
870 $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
873 /* To be created automatically by mail() */
874 if($this->Mailer != 'mail') {
875 if(count($this->to) > 0) {
876 $result .= $this->AddrAppend('To', $this->to);
877 } elseif (count($this->cc) == 0) {
878 $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
883 $from[0][0] = trim($this->From);
884 $from[0][1] = $this->FromName;
885 $result .= $this->AddrAppend('From', $from);
887 /* sendmail and mail() extract Cc from the header before sending */
888 if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
889 $result .= $this->AddrAppend('Cc', $this->cc);
892 /* sendmail and mail() extract Bcc from the header before sending */
893 if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
894 $result .= $this->AddrAppend('Bcc', $this->bcc);
897 if(count($this->ReplyTo) > 0) {
898 $result .= $this->AddrAppend('Reply-To', $this->ReplyTo);
901 /* mail() sets the subject itself */
902 if($this->Mailer != 'mail') {
903 $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
906 if($this->MessageID != '') {
907 $result .= $this->HeaderLine('Message-Id',$this->MessageID);
909 $result .= sprintf("Message-Id: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
911 $result .= $this->HeaderLine('X-Priority', $this->Priority);
912 $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']');
914 if($this->ConfirmReadingTo != '') {
915 $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
918 // Add custom headers
919 for($index = 0; $index < count($this->CustomHeader); $index++) {
920 $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
922 if (!$this->sign_key_file) {
923 $result .= $this->HeaderLine('MIME-Version', '1.0');
924 $result .= $this->GetMailMIME();
931 * Returns the message MIME.
935 function GetMailMIME() {
937 switch($this->message_type) {
939 $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
940 $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
944 case 'alt_attachments':
945 if($this->InlineImageExists()){
946 $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
948 $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
949 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
953 $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
954 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
958 if($this->Mailer != 'mail') {
959 $result .= $this->LE.$this->LE;
966 * Assembles the message body. Returns an empty string on failure.
970 function CreateBody() {
972 if ($this->sign_key_file) {
973 $result .= $this->GetMailMIME();
976 $this->SetWordWrap();
978 switch($this->message_type) {
980 $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
981 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
982 $result .= $this->LE.$this->LE;
983 $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
984 $result .= $this->EncodeString($this->Body, $this->Encoding);
985 $result .= $this->LE.$this->LE;
986 $result .= $this->EndBoundary($this->boundary[1]);
989 $result .= $this->EncodeString($this->Body, $this->Encoding);
992 $result .= $this->GetBoundary($this->boundary[1], '', '', '');
993 $result .= $this->EncodeString($this->Body, $this->Encoding);
994 $result .= $this->LE;
995 $result .= $this->AttachAll();
997 case 'alt_attachments':
998 $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
999 $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
1000 $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
1001 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
1002 $result .= $this->LE.$this->LE;
1003 $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
1004 $result .= $this->EncodeString($this->Body, $this->Encoding);
1005 $result .= $this->LE.$this->LE;
1006 $result .= $this->EndBoundary($this->boundary[2]);
1007 $result .= $this->AttachAll();
1011 if($this->IsError()) {
1013 } else if ($this->sign_key_file) {
1014 $file = tempnam("", "mail");
1015 $fp = fopen($file, "w");
1016 fwrite($fp, $result);
1018 $signed = tempnam("", "signed");
1020 if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), null)) {
1021 $fp = fopen($signed, "r");
1022 $result = fread($fp, filesize($this->sign_key_file));
1025 $result = $result . fread($fp, 1024);
1029 $this->SetError($this->Lang("signing").openssl_error_string());
1041 * Returns the start of a message boundary.
1044 function GetBoundary($boundary, $charSet, $contentType, $encoding) {
1046 if($charSet == '') {
1047 $charSet = $this->CharSet;
1049 if($contentType == '') {
1050 $contentType = $this->ContentType;
1052 if($encoding == '') {
1053 $encoding = $this->Encoding;
1055 $result .= $this->TextLine('--' . $boundary);
1056 $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
1057 $result .= $this->LE;
1058 $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
1059 $result .= $this->LE;
1065 * Returns the end of a message boundary.
1068 function EndBoundary($boundary) {
1069 return $this->LE . '--' . $boundary . '--' . $this->LE;
1073 * Sets the message type.
1077 function SetMessageType() {
1078 if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
1079 $this->message_type = 'plain';
1081 if(count($this->attachment) > 0) {
1082 $this->message_type = 'attachments';
1084 if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
1085 $this->message_type = 'alt';
1087 if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
1088 $this->message_type = 'alt_attachments';
1093 /* Returns a formatted header line.
1097 function HeaderLine($name, $value) {
1098 return $name . ': ' . $value . $this->LE;
1102 * Returns a formatted mail line.
1106 function TextLine($value) {
1107 return $value . $this->LE;
1110 /////////////////////////////////////////////////
1111 // CLASS METHODS, ATTACHMENTS
1112 /////////////////////////////////////////////////
1115 * Adds an attachment from a path on the filesystem.
1116 * Returns false if the file could not be found
1118 * @param string $path Path to the attachment.
1119 * @param string $name Overrides the attachment name.
1120 * @param string $encoding File encoding (see $Encoding).
1121 * @param string $type File extension (MIME) type.
1124 function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
1125 if(!@is_file($path)) {
1126 $this->SetError($this->Lang('file_access') . $path);
1130 $filename = basename($path);
1135 $cur = count($this->attachment);
1136 $this->attachment[$cur][0] = $path;
1137 $this->attachment[$cur][1] = $filename;
1138 $this->attachment[$cur][2] = $name;
1139 $this->attachment[$cur][3] = $encoding;
1140 $this->attachment[$cur][4] = $type;
1141 $this->attachment[$cur][5] = false; // isStringAttachment
1142 $this->attachment[$cur][6] = 'attachment';
1143 $this->attachment[$cur][7] = 0;
1149 * Attaches all fs, string, and binary attachments to the message.
1150 * Returns an empty string on failure.
1154 function AttachAll() {
1155 /* Return text of body */
1158 /* Add all attachments */
1159 for($i = 0; $i < count($this->attachment); $i++) {
1160 /* Check for string attachment */
1161 $bString = $this->attachment[$i][5];
1163 $string = $this->attachment[$i][0];
1165 $path = $this->attachment[$i][0];
1168 $filename = $this->attachment[$i][1];
1169 $name = $this->attachment[$i][2];
1170 $encoding = $this->attachment[$i][3];
1171 $type = $this->attachment[$i][4];
1172 $disposition = $this->attachment[$i][6];
1173 $cid = $this->attachment[$i][7];
1175 $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
1176 $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
1177 $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
1179 if($disposition == 'inline') {
1180 $mime[] = sprintf("Content-Id: <%s>%s", $cid, $this->LE);
1183 $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
1185 /* Encode as string attachment */
1187 $mime[] = $this->EncodeString($string, $encoding);
1188 if($this->IsError()) {
1191 $mime[] = $this->LE.$this->LE;
1193 $mime[] = $this->EncodeFile($path, $encoding);
1194 if($this->IsError()) {
1197 $mime[] = $this->LE.$this->LE;
1201 $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
1203 return join('', $mime);
1207 * Encodes attachment in requested format. Returns an
1208 * empty string on failure.
1212 function EncodeFile ($path, $encoding = 'base64') {
1213 if(!@$fd = fopen($path, 'rb')) {
1214 $this->SetError($this->Lang('file_open') . $path);
1217 $magic_quotes = get_magic_quotes_runtime();
1218 set_magic_quotes_runtime(0);
1219 $file_buffer = fread($fd, filesize($path));
1220 $file_buffer = $this->EncodeString($file_buffer, $encoding);
1222 set_magic_quotes_runtime($magic_quotes);
1224 return $file_buffer;
1228 * Encodes string to requested format. Returns an
1229 * empty string on failure.
1233 function EncodeString ($str, $encoding = 'base64') {
1235 switch(strtolower($encoding)) {
1237 /* chunk_split is found in PHP >= 3.0.6 */
1238 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
1242 $encoded = $this->FixEOL($str);
1243 if (substr($encoded, -(strlen($this->LE))) != $this->LE)
1244 $encoded .= $this->LE;
1249 case 'quoted-printable':
1250 $encoded = $this->EncodeQP($str);
1253 $this->SetError($this->Lang('encoding') . $encoding);
1260 * Encode a header string to best of Q, B, quoted or none.
1264 function EncodeHeader ($str, $position = 'text') {
1267 switch (strtolower($position)) {
1269 if (!preg_match('/[\200-\377]/', $str)) {
1270 /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */
1271 $encoded = addcslashes($str, "\0..\37\177\\\"");
1272 if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
1275 return ("\"$encoded\"");
1278 $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
1281 $x = preg_match_all('/[()"]/', $str, $matches);
1285 $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
1293 $maxlen = 75 - 7 - strlen($this->CharSet);
1294 /* Try to select the encoding which should produce the shortest output */
1295 if (strlen($str)/3 < $x) {
1297 if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
1298 // Use a custom function which correctly encodes and wraps long
1299 // multibyte strings without breaking lines within a character
1300 $encoded = $this->Base64EncodeWrapMB($str);
1302 $encoded = base64_encode($str);
1303 $maxlen -= $maxlen % 4;
1304 $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
1308 $encoded = $this->EncodeQ($str, $position);
1309 $encoded = $this->WrapText($encoded, $maxlen, true);
1310 $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
1313 $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
1314 $encoded = trim(str_replace("\n", $this->LE, $encoded));
1320 * Checks if a string contains multibyte characters.
1322 * @param string $str multi-byte text to wrap encode
1325 function HasMultiBytes($str) {
1326 if (function_exists('mb_strlen')) {
1327 return (strlen($str) > mb_strlen($str, $this->CharSet));
1328 } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
1334 * Correctly encodes and wraps long multibyte strings for mail headers
1335 * without breaking lines within a character.
1336 * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
1338 * @param string $str multi-byte text to wrap encode
1341 function Base64EncodeWrapMB($str) {
1342 $start = "=?".$this->CharSet."?B?";
1346 $mb_length = mb_strlen($str, $this->CharSet);
1347 // Each line must have length <= 75, including $start and $end
1348 $length = 75 - strlen($start) - strlen($end);
1349 // Average multi-byte ratio
1350 $ratio = $mb_length / strlen($str);
1351 // Base64 has a 4:3 ratio
1352 $offset = $avgLength = floor($length * $ratio * .75);
1354 for ($i = 0; $i < $mb_length; $i += $offset) {
1358 $offset = $avgLength - $lookBack;
1359 $chunk = mb_substr($str, $i, $offset, $this->CharSet);
1360 $chunk = base64_encode($chunk);
1363 while (strlen($chunk) > $length);
1365 $encoded .= $chunk . $this->LE;
1368 // Chomp the last linefeed
1369 $encoded = substr($encoded, 0, -strlen($this->LE));
1374 * Encode string to quoted-printable.
1378 function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) {
1379 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
1380 $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
1384 while( list(, $line) = each($lines) ) {
1385 $linlen = strlen($line);
1387 for($i = 0; $i < $linlen; $i++) {
1388 $c = substr( $line, $i, 1 );
1390 if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
1394 if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
1396 } else if ( $space_conv ) {
1399 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
1400 $h2 = floor($dec/16);
1401 $h1 = floor($dec%16);
1402 $c = $escape.$hex[$h2].$hex[$h1];
1404 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
1405 $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
1407 // check if newline first character will be point or not
1414 $output .= $newline.$eol;
1420 * Encode string to q encoding.
1424 function EncodeQ ($str, $position = 'text') {
1425 /* There should not be any EOL in the string */
1426 $encoded = preg_replace("[\r\n]", '', $str);
1428 switch (strtolower($position)) {
1430 $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
1433 $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
1436 /* Replace every high ascii, control =, ? and _ characters */
1437 $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
1438 "'='.sprintf('%02X', ord('\\1'))", $encoded);
1442 /* Replace every spaces to _ (more readable than =20) */
1443 $encoded = str_replace(' ', '_', $encoded);
1449 * Adds a string or binary attachment (non-filesystem) to the list.
1450 * This method can be used to attach ascii or binary data,
1451 * such as a BLOB record from a database.
1452 * @param string $string String attachment data.
1453 * @param string $filename Name of the attachment.
1454 * @param string $encoding File encoding (see $Encoding).
1455 * @param string $type File extension (MIME) type.
1458 function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
1459 /* Append to $attachment array */
1460 $cur = count($this->attachment);
1461 $this->attachment[$cur][0] = $string;
1462 $this->attachment[$cur][1] = $filename;
1463 $this->attachment[$cur][2] = $filename;
1464 $this->attachment[$cur][3] = $encoding;
1465 $this->attachment[$cur][4] = $type;
1466 $this->attachment[$cur][5] = true; // isString
1467 $this->attachment[$cur][6] = 'attachment';
1468 $this->attachment[$cur][7] = 0;
1472 * Adds an embedded attachment. This can include images, sounds, and
1473 * just about any other document. Make sure to set the $type to an
1474 * image type. For JPEG images use "image/jpeg" and for GIF images
1476 * @param string $path Path to the attachment.
1477 * @param string $cid Content id of the attachment. Use this to identify
1478 * the Id for accessing the image in an HTML form.
1479 * @param string $name Overrides the attachment name.
1480 * @param string $encoding File encoding (see $Encoding).
1481 * @param string $type File extension (MIME) type.
1484 function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
1486 if(!@is_file($path)) {
1487 $this->SetError($this->Lang('file_access') . $path);
1491 $filename = basename($path);
1496 /* Append to $attachment array */
1497 $cur = count($this->attachment);
1498 $this->attachment[$cur][0] = $path;
1499 $this->attachment[$cur][1] = $filename;
1500 $this->attachment[$cur][2] = $name;
1501 $this->attachment[$cur][3] = $encoding;
1502 $this->attachment[$cur][4] = $type;
1503 $this->attachment[$cur][5] = false;
1504 $this->attachment[$cur][6] = 'inline';
1505 $this->attachment[$cur][7] = $cid;
1511 * Returns true if an inline attachment is present.
1515 function InlineImageExists() {
1517 for($i = 0; $i < count($this->attachment); $i++) {
1518 if($this->attachment[$i][6] == 'inline') {
1527 /////////////////////////////////////////////////
1528 // CLASS METHODS, MESSAGE RESET
1529 /////////////////////////////////////////////////
1532 * Clears all recipients assigned in the TO array. Returns void.
1535 function ClearAddresses() {
1536 $this->to = array();
1540 * Clears all recipients assigned in the CC array. Returns void.
1543 function ClearCCs() {
1544 $this->cc = array();
1548 * Clears all recipients assigned in the BCC array. Returns void.
1551 function ClearBCCs() {
1552 $this->bcc = array();
1556 * Clears all recipients assigned in the ReplyTo array. Returns void.
1559 function ClearReplyTos() {
1560 $this->ReplyTo = array();
1564 * Clears all recipients assigned in the TO, CC and BCC
1565 * array. Returns void.
1568 function ClearAllRecipients() {
1569 $this->to = array();
1570 $this->cc = array();
1571 $this->bcc = array();
1575 * Clears all previously set filesystem, string, and binary
1576 * attachments. Returns void.
1579 function ClearAttachments() {
1580 $this->attachment = array();
1584 * Clears all custom headers. Returns void.
1587 function ClearCustomHeaders() {
1588 $this->CustomHeader = array();
1591 /////////////////////////////////////////////////
1592 // CLASS METHODS, MISCELLANEOUS
1593 /////////////////////////////////////////////////
1596 * Adds the error message to the error container.
1601 function SetError($msg) {
1602 $this->error_count++;
1603 $this->ErrorInfo = $msg;
1607 * Returns the proper RFC 822 formatted date.
1611 function RFCDate() {
1613 $tzs = ($tz < 0) ? '-' : '+';
1615 $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
1616 $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
1622 * Returns the appropriate server variable. Should work with both
1623 * PHP 4.1.0+ as well as older versions. Returns an empty string
1624 * if nothing is found.
1628 function ServerVar($varName) {
1629 global $HTTP_SERVER_VARS;
1630 global $HTTP_ENV_VARS;
1632 if(!isset($_SERVER)) {
1633 $_SERVER = $HTTP_SERVER_VARS;
1634 if(!isset($_SERVER['REMOTE_ADDR'])) {
1635 $_SERVER = $HTTP_ENV_VARS; // must be Apache
1639 if(isset($_SERVER[$varName])) {
1640 return $_SERVER[$varName];
1647 * Returns the server hostname or 'localhost.localdomain' if unknown.
1651 function ServerHostname() {
1652 if ($this->Hostname != '') {
1653 $result = $this->Hostname;
1654 } elseif ($this->ServerVar('SERVER_NAME') != '') {
1655 $result = $this->ServerVar('SERVER_NAME');
1657 $result = 'localhost.localdomain';
1664 * Returns a message in the appropriate language.
1668 function Lang($key) {
1669 if(count($this->language) < 1) {
1670 $this->SetLanguage('en'); // set the default language
1673 if(isset($this->language[$key])) {
1674 return $this->language[$key];
1676 return 'Language string failed to load: ' . $key;
1681 * Returns true if an error occurred.
1684 function IsError() {
1685 return ($this->error_count > 0);
1689 * Changes every end of line from CR or LF to CRLF.
1693 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.
1704 function AddCustomHeader($custom_header) {
1705 $this->CustomHeader[] = explode(':', $custom_header, 2);
1709 * Evaluates the message and returns modifications for inline images and backgrounds
1713 function MsgHTML($message,$basedir='') {
1714 preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
1715 if(isset($images[2])) {
1716 foreach($images[2] as $i => $url) {
1717 // do not change urls for absolute images (thanks to corvuscorax)
1718 if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) {
1719 $filename = basename($url);
1720 $directory = dirname($url);
1721 ($directory == '.')?$directory='':'';
1722 $cid = 'cid:' . md5($filename);
1723 $fileParts = split("\.", $filename);
1724 $ext = $fileParts[1];
1725 $mimeType = $this->_mime_types($ext);
1726 if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
1727 if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
1728 if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
1729 $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
1734 $this->IsHTML(true);
1735 $this->Body = $message;
1736 $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
1737 if ( !empty($textMsg) && empty($this->AltBody) ) {
1738 $this->AltBody = html_entity_decode($textMsg);
1740 if ( empty($this->AltBody) ) {
1741 $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";
1746 * Gets the mime type of the embedded or inline image
1748 * @return mime type of ext
1750 function _mime_types($ext = '') {
1752 'ai' => 'application/postscript',
1753 'aif' => 'audio/x-aiff',
1754 'aifc' => 'audio/x-aiff',
1755 'aiff' => 'audio/x-aiff',
1756 'avi' => 'video/x-msvideo',
1757 'bin' => 'application/macbinary',
1758 'bmp' => 'image/bmp',
1759 'class' => 'application/octet-stream',
1760 'cpt' => 'application/mac-compactpro',
1761 'css' => 'text/css',
1762 'dcr' => 'application/x-director',
1763 'dir' => 'application/x-director',
1764 'dll' => 'application/octet-stream',
1765 'dms' => 'application/octet-stream',
1766 'doc' => 'application/msword',
1767 'dvi' => 'application/x-dvi',
1768 'dxr' => 'application/x-director',
1769 'eml' => 'message/rfc822',
1770 'eps' => 'application/postscript',
1771 'exe' => 'application/octet-stream',
1772 'gif' => 'image/gif',
1773 'gtar' => 'application/x-gtar',
1774 'htm' => 'text/html',
1775 'html' => 'text/html',
1776 'jpe' => 'image/jpeg',
1777 'jpeg' => 'image/jpeg',
1778 'jpg' => 'image/jpeg',
1779 'hqx' => 'application/mac-binhex40',
1780 'js' => 'application/x-javascript',
1781 'lha' => 'application/octet-stream',
1782 'log' => 'text/plain',
1783 'lzh' => 'application/octet-stream',
1784 'mid' => 'audio/midi',
1785 'midi' => 'audio/midi',
1786 'mif' => 'application/vnd.mif',
1787 'mov' => 'video/quicktime',
1788 'movie' => 'video/x-sgi-movie',
1789 'mp2' => 'audio/mpeg',
1790 'mp3' => 'audio/mpeg',
1791 'mpe' => 'video/mpeg',
1792 'mpeg' => 'video/mpeg',
1793 'mpg' => 'video/mpeg',
1794 'mpga' => 'audio/mpeg',
1795 'oda' => 'application/oda',
1796 'pdf' => 'application/pdf',
1797 'php' => 'application/x-httpd-php',
1798 'php3' => 'application/x-httpd-php',
1799 'php4' => 'application/x-httpd-php',
1800 'phps' => 'application/x-httpd-php-source',
1801 'phtml' => 'application/x-httpd-php',
1802 'png' => 'image/png',
1803 'ppt' => 'application/vnd.ms-powerpoint',
1804 'ps' => 'application/postscript',
1805 'psd' => 'application/octet-stream',
1806 'qt' => 'video/quicktime',
1807 'ra' => 'audio/x-realaudio',
1808 'ram' => 'audio/x-pn-realaudio',
1809 'rm' => 'audio/x-pn-realaudio',
1810 'rpm' => 'audio/x-pn-realaudio-plugin',
1811 'rtf' => 'text/rtf',
1812 'rtx' => 'text/richtext',
1813 'rv' => 'video/vnd.rn-realvideo',
1814 'sea' => 'application/octet-stream',
1815 'shtml' => 'text/html',
1816 'sit' => 'application/x-stuffit',
1817 'so' => 'application/octet-stream',
1818 'smi' => 'application/smil',
1819 'smil' => 'application/smil',
1820 'swf' => 'application/x-shockwave-flash',
1821 'tar' => 'application/x-tar',
1822 'text' => 'text/plain',
1823 'txt' => 'text/plain',
1824 'tgz' => 'application/x-tar',
1825 'tif' => 'image/tiff',
1826 'tiff' => 'image/tiff',
1827 'wav' => 'audio/x-wav',
1828 'wbxml' => 'application/vnd.wap.wbxml',
1829 'wmlc' => 'application/vnd.wap.wmlc',
1830 'word' => 'application/msword',
1831 'xht' => 'application/xhtml+xml',
1832 'xhtml' => 'application/xhtml+xml',
1833 'xl' => 'application/excel',
1834 'xls' => 'application/vnd.ms-excel',
1835 'xml' => 'text/xml',
1836 'xsl' => 'text/xml',
1837 'zip' => 'application/zip'
1839 return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
1843 * Set (or reset) Class Objects (variables)
1846 * $page->set('X-Priority', '3');
1849 * @param string $name Parameter Name
1850 * @param mixed $value Parameter Value
1851 * NOTE: will not work with arrays, there are no arrays to set/reset
1853 function set ( $name, $value = '' ) {
1854 if ( isset($this->$name) ) {
1855 $this->$name = $value;
1857 $this->SetError('Cannot set or reset variable ' . $name);
1863 * Read a file from a supplied filename and return it.
1866 * @param string $filename Parameter File Name
1868 function getFile($filename) {
1870 if ($fp = fopen($filename, 'rb')) {
1871 while (!feof($fp)) {
1872 $return .= fread($fp, 1024);
1882 * Strips newlines to prevent header injection.
1884 * @param string $str String
1887 function SecureHeader($str) {
1889 $str = str_replace("\r", "", $str);
1890 $str = str_replace("\n", "", $str);
1895 * Set the private key file and password to sign the message.
1898 * @param string $key_filename Parameter File Name
1899 * @param string $key_pass Password for private key
1901 function Sign($cert_filename, $key_filename, $key_pass) {
1902 $this->sign_cert_file = $cert_filename;
1903 $this->sign_key_file = $key_filename;
1904 $this->sign_key_pass = $key_pass;