2 /*~ class.phpmailer.php
\r
3 .---------------------------------------------------------------------------.
\r
4 | Software: PHPMailer - PHP email class |
\r
5 | Version: 2.0.0 rc3 |
\r
6 | Contact: via sourceforge.net support pages (also www.codeworxtech.com) |
\r
7 | Info: http://phpmailer.sourceforge.net |
\r
8 | Support: http://sourceforge.net/projects/phpmailer/ |
\r
9 | ------------------------------------------------------------------------- |
\r
10 | Author: Andy Prevost (project admininistrator) |
\r
11 | Author: Brent R. Matzelle (original founder) |
\r
12 | Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. |
\r
13 | Copyright (c) 2001-2003, Brent R. Matzelle |
\r
14 | ------------------------------------------------------------------------- |
\r
15 | License: Distributed under the Lesser General Public License (LGPL) |
\r
16 | http://www.gnu.org/copyleft/lesser.html |
\r
17 | This program is distributed in the hope that it will be useful - WITHOUT |
\r
18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
\r
19 | FITNESS FOR A PARTICULAR PURPOSE. |
\r
20 | ------------------------------------------------------------------------- |
\r
21 | We offer a number of paid services (www.codeworxtech.com): |
\r
22 | - Web Hosting on highly optimized fast and secure servers |
\r
23 | - Technology Consulting |
\r
24 | - Oursourcing (highly qualified programmers and graphic designers) |
\r
25 '---------------------------------------------------------------------------'
\r
28 * PHPMailer - PHP email transport class
\r
29 * @package PHPMailer
\r
30 * @author Andy Prevost
\r
31 * @copyright 2004 - 2007 Andy Prevost
\r
36 /////////////////////////////////////////////////
\r
37 // PROPERTIES, PUBLIC
\r
38 /////////////////////////////////////////////////
\r
41 * Email priority (1 = High, 3 = Normal, 5 = low).
\r
47 * Sets the CharSet of the message.
\r
50 var $CharSet = 'iso-8859-1';
\r
53 * Sets the Content-type of the message.
\r
56 var $ContentType = 'text/plain';
\r
59 * Sets the Encoding of the message. Options for this are "8bit",
\r
60 * "7bit", "binary", "base64", and "quoted-printable".
\r
63 var $Encoding = '8bit';
\r
66 * Holds the most recent mailer error message.
\r
69 var $ErrorInfo = '';
\r
72 * Sets the From email address for the message.
\r
75 var $From = 'root@localhost';
\r
78 * Sets the From name of the message.
\r
81 var $FromName = 'Root User';
\r
84 * Sets the Sender email (Return-Path) of the message. If not empty,
\r
85 * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
\r
91 * Sets the Subject of the message.
\r
97 * Sets the Body of the message. This can be either an HTML or text body.
\r
98 * If HTML then run IsHTML(true).
\r
104 * Sets the text-only body of the message. This automatically sets the
\r
105 * email to multipart/alternative. This body can be read by mail
\r
106 * clients that do not have HTML email capability such as mutt. Clients
\r
107 * that can read HTML will view the normal Body.
\r
113 * Sets word wrapping on the body of the message to a given number of
\r
120 * Method to send mail: ("mail", "sendmail", or "smtp").
\r
123 var $Mailer = 'mail';
\r
126 * Sets the path of the sendmail program.
\r
129 var $Sendmail = '/usr/sbin/sendmail';
\r
132 * Path to PHPMailer plugins. This is now only useful if the SMTP class
\r
133 * is in a different directory than the PHP include path.
\r
136 var $PluginDir = '';
\r
139 * Holds PHPMailer version.
\r
142 var $Version = "2.0.0 rc3";
\r
145 * Sets the email address that a reading confirmation will be sent.
\r
148 var $ConfirmReadingTo = '';
\r
151 * Sets the hostname to use in Message-Id and Received headers
\r
152 * and as default HELO string. If empty, the value returned
\r
153 * by SERVER_NAME is used or 'localhost.localdomain'.
\r
156 var $Hostname = '';
\r
158 /////////////////////////////////////////////////
\r
159 // PROPERTIES FOR SMTP
\r
160 /////////////////////////////////////////////////
\r
163 * Sets the SMTP hosts. All hosts must be separated by a
\r
164 * semicolon. You can also specify a different port
\r
165 * for each host by using this format: [hostname:port]
\r
166 * (e.g. "smtp1.example.com:25;smtp2.example.com").
\r
167 * Hosts will be tried in order.
\r
170 var $Host = 'localhost';
\r
173 * Sets the default SMTP server port.
\r
179 * Sets the SMTP HELO of the message (Default is $Hostname).
\r
185 * Sets connection prefix.
\r
186 * Options are "", "ssl" or "tls"
\r
189 var $SMTPSecure = "";
\r
192 * Sets SMTP authentication. Utilizes the Username and Password variables.
\r
195 var $SMTPAuth = false;
\r
198 * Sets SMTP username.
\r
201 var $Username = '';
\r
204 * Sets SMTP password.
\r
207 var $Password = '';
\r
210 * Sets the SMTP server timeout in seconds. This function will not
\r
211 * work with the win32 version.
\r
217 * Sets SMTP class debugging on or off.
\r
220 var $SMTPDebug = false;
\r
223 * Prevents the SMTP connection from being closed after each mail
\r
224 * sending. If this is set to true then to close the connection
\r
225 * requires an explicit call to SmtpClose().
\r
228 var $SMTPKeepAlive = false;
\r
231 * Provides the ability to have the TO field process individual
\r
232 * emails, instead of sending to entire TO addresses
\r
235 var $SingleTo = false;
\r
237 /////////////////////////////////////////////////
\r
238 // PROPERTIES, PRIVATE
\r
239 /////////////////////////////////////////////////
\r
244 var $bcc = array();
\r
245 var $ReplyTo = array();
\r
246 var $attachment = array();
\r
247 var $CustomHeader = array();
\r
248 var $message_type = '';
\r
249 var $boundary = array();
\r
250 var $language = array();
\r
251 var $error_count = 0;
\r
254 /////////////////////////////////////////////////
\r
255 // METHODS, VARIABLES
\r
256 /////////////////////////////////////////////////
\r
259 * Sets message type to HTML.
\r
260 * @param bool $bool
\r
263 function IsHTML($bool) {
\r
264 if($bool == true) {
\r
265 $this->ContentType = 'text/html';
\r
267 $this->ContentType = 'text/plain';
\r
272 * Sets Mailer to send message using SMTP.
\r
275 function IsSMTP() {
\r
276 $this->Mailer = 'smtp';
\r
280 * Sets Mailer to send message using PHP mail() function.
\r
283 function IsMail() {
\r
284 $this->Mailer = 'mail';
\r
288 * Sets Mailer to send message using the $Sendmail program.
\r
291 function IsSendmail() {
\r
292 $this->Mailer = 'sendmail';
\r
296 * Sets Mailer to send message using the qmail MTA.
\r
299 function IsQmail() {
\r
300 $this->Sendmail = '/var/qmail/bin/sendmail';
\r
301 $this->Mailer = 'sendmail';
\r
304 /////////////////////////////////////////////////
\r
305 // METHODS, RECIPIENTS
\r
306 /////////////////////////////////////////////////
\r
309 * Adds a "To" address.
\r
310 * @param string $address
\r
311 * @param string $name
\r
314 function AddAddress($address, $name = '') {
\r
315 $cur = count($this->to);
\r
316 $this->to[$cur][0] = trim($address);
\r
317 $this->to[$cur][1] = $name;
\r
321 * Adds a "Cc" address. Note: this function works
\r
322 * with the SMTP mailer on win32, not with the "mail"
\r
324 * @param string $address
\r
325 * @param string $name
\r
328 function AddCC($address, $name = '') {
\r
329 $cur = count($this->cc);
\r
330 $this->cc[$cur][0] = trim($address);
\r
331 $this->cc[$cur][1] = $name;
\r
335 * Adds a "Bcc" address. Note: this function works
\r
336 * with the SMTP mailer on win32, not with the "mail"
\r
338 * @param string $address
\r
339 * @param string $name
\r
342 function AddBCC($address, $name = '') {
\r
343 $cur = count($this->bcc);
\r
344 $this->bcc[$cur][0] = trim($address);
\r
345 $this->bcc[$cur][1] = $name;
\r
349 * Adds a "Reply-To" address.
\r
350 * @param string $address
\r
351 * @param string $name
\r
354 function AddReplyTo($address, $name = '') {
\r
355 $cur = count($this->ReplyTo);
\r
356 $this->ReplyTo[$cur][0] = trim($address);
\r
357 $this->ReplyTo[$cur][1] = $name;
\r
360 /////////////////////////////////////////////////
\r
361 // METHODS, MAIL SENDING
\r
362 /////////////////////////////////////////////////
\r
365 * Creates message and assigns Mailer. If the message is
\r
366 * not sent successfully then it returns false. Use the ErrorInfo
\r
367 * variable to view description of the error.
\r
375 if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
\r
376 $this->SetError($this->Lang('provide_address'));
\r
380 /* Set whether the message is multipart/alternative */
\r
381 if(!empty($this->AltBody)) {
\r
382 $this->ContentType = 'multipart/alternative';
\r
385 $this->error_count = 0; // reset errors
\r
386 $this->SetMessageType();
\r
387 $header .= $this->CreateHeader();
\r
388 $body = $this->CreateBody();
\r
394 /* Choose the mailer */
\r
395 switch($this->Mailer) {
\r
397 $result = $this->SendmailSend($header, $body);
\r
400 $result = $this->SmtpSend($header, $body);
\r
403 $result = $this->MailSend($header, $body);
\r
406 $result = $this->MailSend($header, $body);
\r
408 //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
\r
417 * Sends mail using the $Sendmail program.
\r
421 function SendmailSend($header, $body) {
\r
422 if ($this->Sender != '') {
\r
423 $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
\r
425 $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
\r
428 if(!@$mail = popen($sendmail, 'w')) {
\r
429 $this->SetError($this->Lang('execute') . $this->Sendmail);
\r
433 fputs($mail, $header);
\r
434 fputs($mail, $body);
\r
436 $result = pclose($mail) >> 8 & 0xFF;
\r
438 $this->SetError($this->Lang('execute') . $this->Sendmail);
\r
446 * Sends mail using the PHP mail() function.
\r
450 function MailSend($header, $body) {
\r
453 for($i = 0; $i < count($this->to); $i++) {
\r
454 if($i != 0) { $to .= ', '; }
\r
455 $to .= $this->AddrFormat($this->to[$i]);
\r
458 $toArr = split(',', $to);
\r
460 if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) {
\r
461 $old_from = ini_get('sendmail_from');
\r
462 ini_set('sendmail_from', $this->Sender);
\r
463 $params = sprintf("-oi -f %s", $this->Sender);
\r
464 if ($this->SingleTo === true && count($toArr) > 1) {
\r
465 foreach ($toArr as $key => $val) {
\r
466 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
\r
469 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
\r
472 if ($this->SingleTo === true && count($toArr) > 1) {
\r
473 foreach ($toArr as $key => $val) {
\r
474 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
\r
477 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
\r
481 if (isset($old_from)) {
\r
482 ini_set('sendmail_from', $old_from);
\r
486 $this->SetError($this->Lang('instantiate'));
\r
494 * Sends mail via SMTP using PhpSMTP (Author:
\r
495 * Chris Ryan). Returns bool. Returns false if there is a
\r
496 * bad MAIL FROM, RCPT, or DATA input.
\r
500 function SmtpSend($header, $body) {
\r
501 include_once($this->PluginDir . 'class.smtp.php');
\r
503 $bad_rcpt = array();
\r
505 if(!$this->SmtpConnect()) {
\r
509 $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
\r
510 if(!$this->smtp->Mail($smtp_from)) {
\r
511 $error = $this->Lang('from_failed') . $smtp_from;
\r
512 $this->SetError($error);
\r
513 $this->smtp->Reset();
\r
517 /* Attempt to send attach all recipients */
\r
518 for($i = 0; $i < count($this->to); $i++) {
\r
519 if(!$this->smtp->Recipient($this->to[$i][0])) {
\r
520 $bad_rcpt[] = $this->to[$i][0];
\r
523 for($i = 0; $i < count($this->cc); $i++) {
\r
524 if(!$this->smtp->Recipient($this->cc[$i][0])) {
\r
525 $bad_rcpt[] = $this->cc[$i][0];
\r
528 for($i = 0; $i < count($this->bcc); $i++) {
\r
529 if(!$this->smtp->Recipient($this->bcc[$i][0])) {
\r
530 $bad_rcpt[] = $this->bcc[$i][0];
\r
534 if(count($bad_rcpt) > 0) { // Create error message
\r
535 for($i = 0; $i < count($bad_rcpt); $i++) {
\r
539 $error .= $bad_rcpt[$i];
\r
541 $error = $this->Lang('recipients_failed') . $error;
\r
542 $this->SetError($error);
\r
543 $this->smtp->Reset();
\r
547 if(!$this->smtp->Data($header . $body)) {
\r
548 $this->SetError($this->Lang('data_not_accepted'));
\r
549 $this->smtp->Reset();
\r
552 if($this->SMTPKeepAlive == true) {
\r
553 $this->smtp->Reset();
\r
555 $this->SmtpClose();
\r
562 * Initiates a connection to an SMTP server. Returns false if the
\r
563 * operation failed.
\r
567 function SmtpConnect() {
\r
568 if($this->smtp == NULL) {
\r
569 $this->smtp = new SMTP();
\r
572 $this->smtp->do_debug = $this->SMTPDebug;
\r
573 $hosts = explode(';', $this->Host);
\r
575 $connection = ($this->smtp->Connected());
\r
577 /* Retry while there is no connection */
\r
578 while($index < count($hosts) && $connection == false) {
\r
579 $hostinfo = array();
\r
580 if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
\r
581 $host = $hostinfo[1];
\r
582 $port = $hostinfo[2];
\r
584 $host = $hosts[$index];
\r
585 $port = $this->Port;
\r
588 if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) {
\r
589 if ($this->Helo != '') {
\r
590 $this->smtp->Hello($this->Helo);
\r
592 $this->smtp->Hello($this->ServerHostname());
\r
595 $connection = true;
\r
596 if($this->SMTPAuth) {
\r
597 if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
\r
598 $this->SetError($this->Lang('authenticate'));
\r
599 $this->smtp->Reset();
\r
600 $connection = false;
\r
607 $this->SetError($this->Lang('connect_host'));
\r
610 return $connection;
\r
614 * Closes the active SMTP session if one exists.
\r
617 function SmtpClose() {
\r
618 if($this->smtp != NULL) {
\r
619 if($this->smtp->Connected()) {
\r
620 $this->smtp->Quit();
\r
621 $this->smtp->Close();
\r
627 * Sets the language for all class error messages. Returns false
\r
628 * if it cannot load the language file. The default language type
\r
630 * @param string $lang_type Type of language (e.g. Portuguese: "br")
\r
631 * @param string $lang_path Path to the language file directory
\r
635 function SetLanguage($lang_type, $lang_path = 'language/') {
\r
636 if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
\r
637 include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
\r
638 } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) {
\r
639 include($lang_path.'phpmailer.lang-en.php');
\r
641 $this->SetError('Could not load language file');
\r
644 $this->language = $PHPMAILER_LANG;
\r
649 /////////////////////////////////////////////////
\r
650 // METHODS, MESSAGE CREATION
\r
651 /////////////////////////////////////////////////
\r
654 * Creates recipient headers.
\r
658 function AddrAppend($type, $addr) {
\r
659 $addr_str = $type . ': ';
\r
660 $addr_str .= $this->AddrFormat($addr[0]);
\r
661 if(count($addr) > 1) {
\r
662 for($i = 1; $i < count($addr); $i++) {
\r
663 $addr_str .= ', ' . $this->AddrFormat($addr[$i]);
\r
666 $addr_str .= $this->LE;
\r
672 * Formats an address correctly.
\r
676 function AddrFormat($addr) {
\r
677 if(empty($addr[1])) {
\r
678 $formatted = $this->SecureHeader($addr[0]);
\r
680 $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
\r
687 * Wraps message for use with mailers that do not
\r
688 * automatically perform wrapping and for quoted-printable.
\r
689 * Original written by philippe.
\r
693 function WrapText($message, $length, $qp_mode = false) {
\r
694 $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
\r
696 $message = $this->FixEOL($message);
\r
697 if (substr($message, -1) == $this->LE) {
\r
698 $message = substr($message, 0, -1);
\r
701 $line = explode($this->LE, $message);
\r
703 for ($i=0 ;$i < count($line); $i++) {
\r
704 $line_part = explode(' ', $line[$i]);
\r
706 for ($e = 0; $e<count($line_part); $e++) {
\r
707 $word = $line_part[$e];
\r
708 if ($qp_mode and (strlen($word) > $length)) {
\r
709 $space_left = $length - strlen($buf) - 1;
\r
711 if ($space_left > 20) {
\r
712 $len = $space_left;
\r
713 if (substr($word, $len - 1, 1) == '=') {
\r
715 } elseif (substr($word, $len - 2, 1) == '=') {
\r
718 $part = substr($word, 0, $len);
\r
719 $word = substr($word, $len);
\r
720 $buf .= ' ' . $part;
\r
721 $message .= $buf . sprintf("=%s", $this->LE);
\r
723 $message .= $buf . $soft_break;
\r
727 while (strlen($word) > 0) {
\r
729 if (substr($word, $len - 1, 1) == '=') {
\r
731 } elseif (substr($word, $len - 2, 1) == '=') {
\r
734 $part = substr($word, 0, $len);
\r
735 $word = substr($word, $len);
\r
737 if (strlen($word) > 0) {
\r
738 $message .= $part . sprintf("=%s", $this->LE);
\r
745 $buf .= ($e == 0) ? $word : (' ' . $word);
\r
747 if (strlen($buf) > $length and $buf_o != '') {
\r
748 $message .= $buf_o . $soft_break;
\r
753 $message .= $buf . $this->LE;
\r
760 * Set the body wrapping.
\r
764 function SetWordWrap() {
\r
765 if($this->WordWrap < 1) {
\r
769 switch($this->message_type) {
\r
772 case 'alt_attachments':
\r
773 $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
\r
776 $this->Body = $this->WrapText($this->Body, $this->WordWrap);
\r
782 * Assembles message header.
\r
786 function CreateHeader() {
\r
789 /* Set the boundaries */
\r
790 $uniq_id = md5(uniqid(time()));
\r
791 $this->boundary[1] = 'b1_' . $uniq_id;
\r
792 $this->boundary[2] = 'b2_' . $uniq_id;
\r
794 $result .= $this->HeaderLine('Date', $this->RFCDate());
\r
795 if($this->Sender == '') {
\r
796 $result .= $this->HeaderLine('Return-Path', trim($this->From));
\r
798 $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
\r
801 /* To be created automatically by mail() */
\r
802 if($this->Mailer != 'mail') {
\r
803 if(count($this->to) > 0) {
\r
804 $result .= $this->AddrAppend('To', $this->to);
\r
805 } elseif (count($this->cc) == 0) {
\r
806 $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
\r
808 if(count($this->cc) > 0) {
\r
809 $result .= $this->AddrAppend('Cc', $this->cc);
\r
814 $from[0][0] = trim($this->From);
\r
815 $from[0][1] = $this->FromName;
\r
816 $result .= $this->AddrAppend('From', $from);
\r
818 /* sendmail and mail() extract Cc from the header before sending */
\r
819 if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
\r
820 $result .= $this->AddrAppend('Cc', $this->cc);
\r
823 /* sendmail and mail() extract Bcc from the header before sending */
\r
824 if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
\r
825 $result .= $this->AddrAppend('Bcc', $this->bcc);
\r
828 if(count($this->ReplyTo) > 0) {
\r
829 $result .= $this->AddrAppend('Reply-To', $this->ReplyTo);
\r
832 /* mail() sets the subject itself */
\r
833 if($this->Mailer != 'mail') {
\r
834 $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
\r
837 $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
\r
838 $result .= $this->HeaderLine('X-Priority', $this->Priority);
\r
839 $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']');
\r
841 if($this->ConfirmReadingTo != '') {
\r
842 $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
\r
845 // Add custom headers
\r
846 for($index = 0; $index < count($this->CustomHeader); $index++) {
\r
847 $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
\r
849 $result .= $this->HeaderLine('MIME-Version', '1.0');
\r
851 switch($this->message_type) {
\r
853 $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
\r
854 $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
\r
856 case 'attachments':
\r
858 case 'alt_attachments':
\r
859 if($this->InlineImageExists()){
\r
860 $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
\r
862 $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
\r
863 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
\r
867 $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
\r
868 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
\r
872 if($this->Mailer != 'mail') {
\r
873 $result .= $this->LE.$this->LE;
\r
880 * Assembles the message body. Returns an empty string on failure.
\r
884 function CreateBody() {
\r
887 $this->SetWordWrap();
\r
889 switch($this->message_type) {
\r
891 $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
\r
892 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
\r
893 $result .= $this->LE.$this->LE;
\r
894 $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
\r
895 $result .= $this->EncodeString($this->Body, $this->Encoding);
\r
896 $result .= $this->LE.$this->LE;
\r
897 $result .= $this->EndBoundary($this->boundary[1]);
\r
900 $result .= $this->EncodeString($this->Body, $this->Encoding);
\r
902 case 'attachments':
\r
903 $result .= $this->GetBoundary($this->boundary[1], '', '', '');
\r
904 $result .= $this->EncodeString($this->Body, $this->Encoding);
\r
905 $result .= $this->LE;
\r
906 $result .= $this->AttachAll();
\r
908 case 'alt_attachments':
\r
909 $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
\r
910 $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
\r
911 $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
\r
912 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
\r
913 $result .= $this->LE.$this->LE;
\r
914 $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
\r
915 $result .= $this->EncodeString($this->Body, $this->Encoding);
\r
916 $result .= $this->LE.$this->LE;
\r
917 $result .= $this->EndBoundary($this->boundary[2]);
\r
918 $result .= $this->AttachAll();
\r
921 if($this->IsError()) {
\r
929 * Returns the start of a message boundary.
\r
932 function GetBoundary($boundary, $charSet, $contentType, $encoding) {
\r
934 if($charSet == '') {
\r
935 $charSet = $this->CharSet;
\r
937 if($contentType == '') {
\r
938 $contentType = $this->ContentType;
\r
940 if($encoding == '') {
\r
941 $encoding = $this->Encoding;
\r
943 $result .= $this->TextLine('--' . $boundary);
\r
944 $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
\r
945 $result .= $this->LE;
\r
946 $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
\r
947 $result .= $this->LE;
\r
953 * Returns the end of a message boundary.
\r
956 function EndBoundary($boundary) {
\r
957 return $this->LE . '--' . $boundary . '--' . $this->LE;
\r
961 * Sets the message type.
\r
965 function SetMessageType() {
\r
966 if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
\r
967 $this->message_type = 'plain';
\r
969 if(count($this->attachment) > 0) {
\r
970 $this->message_type = 'attachments';
\r
972 if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
\r
973 $this->message_type = 'alt';
\r
975 if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
\r
976 $this->message_type = 'alt_attachments';
\r
981 /* Returns a formatted header line.
\r
985 function HeaderLine($name, $value) {
\r
986 return $name . ': ' . $value . $this->LE;
\r
990 * Returns a formatted mail line.
\r
994 function TextLine($value) {
\r
995 return $value . $this->LE;
\r
998 /////////////////////////////////////////////////
\r
999 // CLASS METHODS, ATTACHMENTS
\r
1000 /////////////////////////////////////////////////
\r
1003 * Adds an attachment from a path on the filesystem.
\r
1004 * Returns false if the file could not be found
\r
1006 * @param string $path Path to the attachment.
\r
1007 * @param string $name Overrides the attachment name.
\r
1008 * @param string $encoding File encoding (see $Encoding).
\r
1009 * @param string $type File extension (MIME) type.
\r
1012 function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
\r
1013 if(!@is_file($path)) {
\r
1014 $this->SetError($this->Lang('file_access') . $path);
\r
1018 $filename = basename($path);
\r
1020 $name = $filename;
\r
1023 $cur = count($this->attachment);
\r
1024 $this->attachment[$cur][0] = $path;
\r
1025 $this->attachment[$cur][1] = $filename;
\r
1026 $this->attachment[$cur][2] = $name;
\r
1027 $this->attachment[$cur][3] = $encoding;
\r
1028 $this->attachment[$cur][4] = $type;
\r
1029 $this->attachment[$cur][5] = false; // isStringAttachment
\r
1030 $this->attachment[$cur][6] = 'attachment';
\r
1031 $this->attachment[$cur][7] = 0;
\r
1037 * Attaches all fs, string, and binary attachments to the message.
\r
1038 * Returns an empty string on failure.
\r
1042 function AttachAll() {
\r
1043 /* Return text of body */
\r
1046 /* Add all attachments */
\r
1047 for($i = 0; $i < count($this->attachment); $i++) {
\r
1048 /* Check for string attachment */
\r
1049 $bString = $this->attachment[$i][5];
\r
1051 $string = $this->attachment[$i][0];
\r
1053 $path = $this->attachment[$i][0];
\r
1056 $filename = $this->attachment[$i][1];
\r
1057 $name = $this->attachment[$i][2];
\r
1058 $encoding = $this->attachment[$i][3];
\r
1059 $type = $this->attachment[$i][4];
\r
1060 $disposition = $this->attachment[$i][6];
\r
1061 $cid = $this->attachment[$i][7];
\r
1063 $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
\r
1064 $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
\r
1065 $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
\r
1067 if($disposition == 'inline') {
\r
1068 $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
\r
1071 $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $name, $this->LE.$this->LE);
\r
1073 /* Encode as string attachment */
\r
1075 $mime[] = $this->EncodeString($string, $encoding);
\r
1076 if($this->IsError()) {
\r
1079 $mime[] = $this->LE.$this->LE;
\r
1081 $mime[] = $this->EncodeFile($path, $encoding);
\r
1082 if($this->IsError()) {
\r
1085 $mime[] = $this->LE.$this->LE;
\r
1089 $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
\r
1091 return join('', $mime);
\r
1095 * Encodes attachment in requested format. Returns an
\r
1096 * empty string on failure.
\r
1100 function EncodeFile ($path, $encoding = 'base64') {
\r
1101 if(!@$fd = fopen($path, 'rb')) {
\r
1102 $this->SetError($this->Lang('file_open') . $path);
\r
1105 $magic_quotes = get_magic_quotes_runtime();
\r
1106 set_magic_quotes_runtime(0);
\r
1107 $file_buffer = fread($fd, filesize($path));
\r
1108 $file_buffer = $this->EncodeString($file_buffer, $encoding);
\r
1110 set_magic_quotes_runtime($magic_quotes);
\r
1112 return $file_buffer;
\r
1116 * Encodes string to requested format. Returns an
\r
1117 * empty string on failure.
\r
1121 function EncodeString ($str, $encoding = 'base64') {
\r
1123 switch(strtolower($encoding)) {
\r
1125 /* chunk_split is found in PHP >= 3.0.6 */
\r
1126 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
\r
1130 $encoded = $this->FixEOL($str);
\r
1131 if (substr($encoded, -(strlen($this->LE))) != $this->LE)
\r
1132 $encoded .= $this->LE;
\r
1137 case 'quoted-printable':
\r
1138 $encoded = $this->EncodeQP($str);
\r
1141 $this->SetError($this->Lang('encoding') . $encoding);
\r
1148 * Encode a header string to best of Q, B, quoted or none.
\r
1152 function EncodeHeader ($str, $position = 'text') {
\r
1155 switch (strtolower($position)) {
\r
1157 if (!preg_match('/[\200-\377]/', $str)) {
\r
1158 /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */
\r
1159 $encoded = addcslashes($str, "\0..\37\177\\\"");
\r
1160 if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
\r
1161 return ($encoded);
\r
1163 return ("\"$encoded\"");
\r
1166 $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
\r
1169 $x = preg_match_all('/[()"]/', $str, $matches);
\r
1170 /* Fall-through */
\r
1173 $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
\r
1181 $maxlen = 75 - 7 - strlen($this->CharSet);
\r
1182 /* Try to select the encoding which should produce the shortest output */
\r
1183 if (strlen($str)/3 < $x) {
\r
1185 $encoded = base64_encode($str);
\r
1186 $maxlen -= $maxlen % 4;
\r
1187 $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
\r
1190 $encoded = $this->EncodeQ($str, $position);
\r
1191 $encoded = $this->WrapText($encoded, $maxlen, true);
\r
1192 $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
\r
1195 $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
\r
1196 $encoded = trim(str_replace("\n", $this->LE, $encoded));
\r
1202 * Encode string to quoted-printable.
\r
1206 function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) {
\r
1207 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
\r
1208 $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
\r
1212 while( list(, $line) = each($lines) ) {
\r
1213 $linlen = strlen($line);
\r
1215 for($i = 0; $i < $linlen; $i++) {
\r
1216 $c = substr( $line, $i, 1 );
\r
1218 if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
\r
1221 if ( $dec == 32 ) {
\r
1222 if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
\r
1224 } else if ( $space_conv ) {
\r
1227 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
\r
1228 $h2 = floor($dec/16);
\r
1229 $h1 = floor($dec%16);
\r
1230 $c = $escape.$hex[$h2].$hex[$h1];
\r
1232 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
\r
1233 $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
\r
1235 // check if newline first character will be point or not
\r
1236 if ( $dec == 46 ) {
\r
1242 $output .= $newline.$eol;
\r
1244 return trim($output);
\r
1248 * Encode string to q encoding.
\r
1252 function EncodeQ ($str, $position = 'text') {
\r
1253 /* There should not be any EOL in the string */
\r
1254 $encoded = preg_replace("[\r\n]", '', $str);
\r
1256 switch (strtolower($position)) {
\r
1258 $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
\r
1261 $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
\r
1264 /* Replace every high ascii, control =, ? and _ characters */
\r
1265 $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
\r
1266 "'='.sprintf('%02X', ord('\\1'))", $encoded);
\r
1270 /* Replace every spaces to _ (more readable than =20) */
\r
1271 $encoded = str_replace(' ', '_', $encoded);
\r
1277 * Adds a string or binary attachment (non-filesystem) to the list.
\r
1278 * This method can be used to attach ascii or binary data,
\r
1279 * such as a BLOB record from a database.
\r
1280 * @param string $string String attachment data.
\r
1281 * @param string $filename Name of the attachment.
\r
1282 * @param string $encoding File encoding (see $Encoding).
\r
1283 * @param string $type File extension (MIME) type.
\r
1286 function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
\r
1287 /* Append to $attachment array */
\r
1288 $cur = count($this->attachment);
\r
1289 $this->attachment[$cur][0] = $string;
\r
1290 $this->attachment[$cur][1] = $filename;
\r
1291 $this->attachment[$cur][2] = $filename;
\r
1292 $this->attachment[$cur][3] = $encoding;
\r
1293 $this->attachment[$cur][4] = $type;
\r
1294 $this->attachment[$cur][5] = true; // isString
\r
1295 $this->attachment[$cur][6] = 'attachment';
\r
1296 $this->attachment[$cur][7] = 0;
\r
1300 * Adds an embedded attachment. This can include images, sounds, and
\r
1301 * just about any other document. Make sure to set the $type to an
\r
1302 * image type. For JPEG images use "image/jpeg" and for GIF images
\r
1303 * use "image/gif".
\r
1304 * @param string $path Path to the attachment.
\r
1305 * @param string $cid Content ID of the attachment. Use this to identify
\r
1306 * the Id for accessing the image in an HTML form.
\r
1307 * @param string $name Overrides the attachment name.
\r
1308 * @param string $encoding File encoding (see $Encoding).
\r
1309 * @param string $type File extension (MIME) type.
\r
1312 function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
\r
1314 if(!@is_file($path)) {
\r
1315 $this->SetError($this->Lang('file_access') . $path);
\r
1319 $filename = basename($path);
\r
1321 $name = $filename;
\r
1324 /* Append to $attachment array */
\r
1325 $cur = count($this->attachment);
\r
1326 $this->attachment[$cur][0] = $path;
\r
1327 $this->attachment[$cur][1] = $filename;
\r
1328 $this->attachment[$cur][2] = $name;
\r
1329 $this->attachment[$cur][3] = $encoding;
\r
1330 $this->attachment[$cur][4] = $type;
\r
1331 $this->attachment[$cur][5] = false;
\r
1332 $this->attachment[$cur][6] = 'inline';
\r
1333 $this->attachment[$cur][7] = $cid;
\r
1339 * Returns true if an inline attachment is present.
\r
1343 function InlineImageExists() {
\r
1345 for($i = 0; $i < count($this->attachment); $i++) {
\r
1346 if($this->attachment[$i][6] == 'inline') {
\r
1355 /////////////////////////////////////////////////
\r
1356 // CLASS METHODS, MESSAGE RESET
\r
1357 /////////////////////////////////////////////////
\r
1360 * Clears all recipients assigned in the TO array. Returns void.
\r
1363 function ClearAddresses() {
\r
1364 $this->to = array();
\r
1368 * Clears all recipients assigned in the CC array. Returns void.
\r
1371 function ClearCCs() {
\r
1372 $this->cc = array();
\r
1376 * Clears all recipients assigned in the BCC array. Returns void.
\r
1379 function ClearBCCs() {
\r
1380 $this->bcc = array();
\r
1384 * Clears all recipients assigned in the ReplyTo array. Returns void.
\r
1387 function ClearReplyTos() {
\r
1388 $this->ReplyTo = array();
\r
1392 * Clears all recipients assigned in the TO, CC and BCC
\r
1393 * array. Returns void.
\r
1396 function ClearAllRecipients() {
\r
1397 $this->to = array();
\r
1398 $this->cc = array();
\r
1399 $this->bcc = array();
\r
1403 * Clears all previously set filesystem, string, and binary
\r
1404 * attachments. Returns void.
\r
1407 function ClearAttachments() {
\r
1408 $this->attachment = array();
\r
1412 * Clears all custom headers. Returns void.
\r
1415 function ClearCustomHeaders() {
\r
1416 $this->CustomHeader = array();
\r
1419 /////////////////////////////////////////////////
\r
1420 // CLASS METHODS, MISCELLANEOUS
\r
1421 /////////////////////////////////////////////////
\r
1424 * Adds the error message to the error container.
\r
1429 function SetError($msg) {
\r
1430 $this->error_count++;
\r
1431 $this->ErrorInfo = $msg;
\r
1435 * Returns the proper RFC 822 formatted date.
\r
1439 function RFCDate() {
\r
1441 $tzs = ($tz < 0) ? '-' : '+';
\r
1443 $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
\r
1444 $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
\r
1450 * Returns the appropriate server variable. Should work with both
\r
1451 * PHP 4.1.0+ as well as older versions. Returns an empty string
\r
1452 * if nothing is found.
\r
1456 function ServerVar($varName) {
\r
1457 global $HTTP_SERVER_VARS;
\r
1458 global $HTTP_ENV_VARS;
\r
1460 if(!isset($_SERVER)) {
\r
1461 $_SERVER = $HTTP_SERVER_VARS;
\r
1462 if(!isset($_SERVER['REMOTE_ADDR'])) {
\r
1463 $_SERVER = $HTTP_ENV_VARS; // must be Apache
\r
1467 if(isset($_SERVER[$varName])) {
\r
1468 return $_SERVER[$varName];
\r
1475 * Returns the server hostname or 'localhost.localdomain' if unknown.
\r
1479 function ServerHostname() {
\r
1480 if ($this->Hostname != '') {
\r
1481 $result = $this->Hostname;
\r
1482 } elseif ($this->ServerVar('SERVER_NAME') != '') {
\r
1483 $result = $this->ServerVar('SERVER_NAME');
\r
1485 $result = 'localhost.localdomain';
\r
1492 * Returns a message in the appropriate language.
\r
1496 function Lang($key) {
\r
1497 if(count($this->language) < 1) {
\r
1498 $this->SetLanguage('en'); // set the default language
\r
1501 if(isset($this->language[$key])) {
\r
1502 return $this->language[$key];
\r
1504 return 'Language string failed to load: ' . $key;
\r
1509 * Returns true if an error occurred.
\r
1512 function IsError() {
\r
1513 return ($this->error_count > 0);
\r
1517 * Changes every end of line from CR or LF to CRLF.
\r
1521 function FixEOL($str) {
\r
1522 $str = str_replace("\r\n", "\n", $str);
\r
1523 $str = str_replace("\r", "\n", $str);
\r
1524 $str = str_replace("\n", $this->LE, $str);
\r
1529 * Adds a custom header.
\r
1532 function AddCustomHeader($custom_header) {
\r
1533 $this->CustomHeader[] = explode(':', $custom_header, 2);
\r
1537 * Evaluates the message and returns modifications for inline images and backgrounds
\r
1539 * @return $message
\r
1541 function MsgHTML($message) {
\r
1542 preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
\r
1543 if(isset($images[2])) {
\r
1544 foreach($images[2] as $i => $url) {
\r
1545 $filename = basename($url);
\r
1546 $directory = dirname($url);
\r
1547 $cid = 'cid:' . md5($filename);
\r
1548 $fileParts = split("\.", $filename);
\r
1549 $ext = $fileParts[1];
\r
1550 $mimeType = $this->_mime_types($ext);
\r
1551 $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
\r
1552 $this->AddEmbeddedImage($url, md5($filename), $filename, 'base64', $mimeType);
\r
1555 $this->IsHTML(true);
\r
1556 $this->Body = $message;
\r
1557 $textMsg = trim(strip_tags($message));
\r
1558 if ( !empty($textMsg) && empty($this->AltBody) ) {
\r
1559 $this->AltBody = $textMsg;
\r
1561 if ( empty($this->AltBody) ) {
\r
1562 $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";
\r
1567 * Gets the mime type of the embedded or inline image
\r
1569 * @return mime type of ext
\r
1571 function _mime_types($ext = '') {
\r
1573 'hqx' => 'application/mac-binhex40',
\r
1574 'cpt' => 'application/mac-compactpro',
\r
1575 'doc' => 'application/msword',
\r
1576 'bin' => 'application/macbinary',
\r
1577 'dms' => 'application/octet-stream',
\r
1578 'lha' => 'application/octet-stream',
\r
1579 'lzh' => 'application/octet-stream',
\r
1580 'exe' => 'application/octet-stream',
\r
1581 'class' => 'application/octet-stream',
\r
1582 'psd' => 'application/octet-stream',
\r
1583 'so' => 'application/octet-stream',
\r
1584 'sea' => 'application/octet-stream',
\r
1585 'dll' => 'application/octet-stream',
\r
1586 'oda' => 'application/oda',
\r
1587 'pdf' => 'application/pdf',
\r
1588 'ai' => 'application/postscript',
\r
1589 'eps' => 'application/postscript',
\r
1590 'ps' => 'application/postscript',
\r
1591 'smi' => 'application/smil',
\r
1592 'smil' => 'application/smil',
\r
1593 'mif' => 'application/vnd.mif',
\r
1594 'xls' => 'application/vnd.ms-excel',
\r
1595 'ppt' => 'application/vnd.ms-powerpoint',
\r
1596 'wbxml' => 'application/vnd.wap.wbxml',
\r
1597 'wmlc' => 'application/vnd.wap.wmlc',
\r
1598 'dcr' => 'application/x-director',
\r
1599 'dir' => 'application/x-director',
\r
1600 'dxr' => 'application/x-director',
\r
1601 'dvi' => 'application/x-dvi',
\r
1602 'gtar' => 'application/x-gtar',
\r
1603 'php' => 'application/x-httpd-php',
\r
1604 'php4' => 'application/x-httpd-php',
\r
1605 'php3' => 'application/x-httpd-php',
\r
1606 'phtml' => 'application/x-httpd-php',
\r
1607 'phps' => 'application/x-httpd-php-source',
\r
1608 'js' => 'application/x-javascript',
\r
1609 'swf' => 'application/x-shockwave-flash',
\r
1610 'sit' => 'application/x-stuffit',
\r
1611 'tar' => 'application/x-tar',
\r
1612 'tgz' => 'application/x-tar',
\r
1613 'xhtml' => 'application/xhtml+xml',
\r
1614 'xht' => 'application/xhtml+xml',
\r
1615 'zip' => 'application/zip',
\r
1616 'mid' => 'audio/midi',
\r
1617 'midi' => 'audio/midi',
\r
1618 'mpga' => 'audio/mpeg',
\r
1619 'mp2' => 'audio/mpeg',
\r
1620 'mp3' => 'audio/mpeg',
\r
1621 'aif' => 'audio/x-aiff',
\r
1622 'aiff' => 'audio/x-aiff',
\r
1623 'aifc' => 'audio/x-aiff',
\r
1624 'ram' => 'audio/x-pn-realaudio',
\r
1625 'rm' => 'audio/x-pn-realaudio',
\r
1626 'rpm' => 'audio/x-pn-realaudio-plugin',
\r
1627 'ra' => 'audio/x-realaudio',
\r
1628 'rv' => 'video/vnd.rn-realvideo',
\r
1629 'wav' => 'audio/x-wav',
\r
1630 'bmp' => 'image/bmp',
\r
1631 'gif' => 'image/gif',
\r
1632 'jpeg' => 'image/jpeg',
\r
1633 'jpg' => 'image/jpeg',
\r
1634 'jpe' => 'image/jpeg',
\r
1635 'png' => 'image/png',
\r
1636 'tiff' => 'image/tiff',
\r
1637 'tif' => 'image/tiff',
\r
1638 'css' => 'text/css',
\r
1639 'html' => 'text/html',
\r
1640 'htm' => 'text/html',
\r
1641 'shtml' => 'text/html',
\r
1642 'txt' => 'text/plain',
\r
1643 'text' => 'text/plain',
\r
1644 'log' => 'text/plain',
\r
1645 'rtx' => 'text/richtext',
\r
1646 'rtf' => 'text/rtf',
\r
1647 'xml' => 'text/xml',
\r
1648 'xsl' => 'text/xml',
\r
1649 'mpeg' => 'video/mpeg',
\r
1650 'mpg' => 'video/mpeg',
\r
1651 'mpe' => 'video/mpeg',
\r
1652 'qt' => 'video/quicktime',
\r
1653 'mov' => 'video/quicktime',
\r
1654 'avi' => 'video/x-msvideo',
\r
1655 'movie' => 'video/x-sgi-movie',
\r
1656 'doc' => 'application/msword',
\r
1657 'word' => 'application/msword',
\r
1658 'xl' => 'application/excel',
\r
1659 'eml' => 'message/rfc822'
\r
1661 return ( ! isset($mimes[strtolower($ext)])) ? 'application/x-unknown-content-type' : $mimes[strtolower($ext)];
\r
1665 * Set (or reset) Class Objects (variables)
\r
1668 * $page->set('X-Priority', '3');
\r
1671 * @param string $name Parameter Name
\r
1672 * @param mixed $value Parameter Value
\r
1673 * NOTE: will not work with arrays, there are no arrays to set/reset
\r
1675 function set ( $name, $value = '' ) {
\r
1676 if ( isset($this->$name) ) {
\r
1677 $this->$name = $value;
\r
1679 $this->SetError('Cannot set or reset variable ' . $name);
\r
1685 * Read a file from a supplied filename and return it.
\r
1688 * @param string $filename Parameter File Name
\r
1690 function getFile($filename) {
\r
1692 if ($fp = fopen($filename, 'rb')) {
\r
1693 while (!feof($fp)) {
\r
1694 $return .= fread($fp, 1024);
\r
1704 * Strips newlines to prevent header injection.
\r
1706 * @param string $str String
\r
1709 function SecureHeader($str) {
\r
1710 $str = trim($str);
\r
1711 $str = str_replace("\r", "", $str);
\r
1712 $str = str_replace("\n", "", $str);
\r