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.2";
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_key_file = "";
261 var $sign_key_pass = "";
263 /////////////////////////////////////////////////
264 // METHODS, VARIABLES
265 /////////////////////////////////////////////////
268 * Sets message type to HTML.
272 function IsHTML($bool) {
274 $this->ContentType = 'text/html';
276 $this->ContentType = 'text/plain';
281 * Sets Mailer to send message using SMTP.
285 $this->Mailer = 'smtp';
289 * Sets Mailer to send message using PHP mail() function.
293 $this->Mailer = 'mail';
297 * Sets Mailer to send message using the $Sendmail program.
300 function IsSendmail() {
301 $this->Mailer = 'sendmail';
305 * Sets Mailer to send message using the qmail MTA.
309 $this->Sendmail = '/var/qmail/bin/sendmail';
310 $this->Mailer = 'sendmail';
313 /////////////////////////////////////////////////
314 // METHODS, RECIPIENTS
315 /////////////////////////////////////////////////
318 * Adds a "To" address.
319 * @param string $address
320 * @param string $name
323 function AddAddress($address, $name = '') {
324 $cur = count($this->to);
325 $this->to[$cur][0] = trim($address);
326 $this->to[$cur][1] = $name;
330 * Adds a "Cc" address. Note: this function works
331 * with the SMTP mailer on win32, not with the "mail"
333 * @param string $address
334 * @param string $name
337 function AddCC($address, $name = '') {
338 $cur = count($this->cc);
339 $this->cc[$cur][0] = trim($address);
340 $this->cc[$cur][1] = $name;
344 * Adds a "Bcc" address. Note: this function works
345 * with the SMTP mailer on win32, not with the "mail"
347 * @param string $address
348 * @param string $name
351 function AddBCC($address, $name = '') {
352 $cur = count($this->bcc);
353 $this->bcc[$cur][0] = trim($address);
354 $this->bcc[$cur][1] = $name;
358 * Adds a "Reply-To" address.
359 * @param string $address
360 * @param string $name
363 function AddReplyTo($address, $name = '') {
364 $cur = count($this->ReplyTo);
365 $this->ReplyTo[$cur][0] = trim($address);
366 $this->ReplyTo[$cur][1] = $name;
369 /////////////////////////////////////////////////
370 // METHODS, MAIL SENDING
371 /////////////////////////////////////////////////
374 * Creates message and assigns Mailer. If the message is
375 * not sent successfully then it returns false. Use the ErrorInfo
376 * variable to view description of the error.
384 if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
385 $this->SetError($this->Lang('provide_address'));
389 /* Set whether the message is multipart/alternative */
390 if(!empty($this->AltBody)) {
391 $this->ContentType = 'multipart/alternative';
394 $this->error_count = 0; // reset errors
395 $this->SetMessageType();
396 $header .= $this->CreateHeader();
397 $body = $this->CreateBody();
403 /* Choose the mailer */
404 switch($this->Mailer) {
406 $result = $this->SendmailSend($header, $body);
409 $result = $this->SmtpSend($header, $body);
412 $result = $this->MailSend($header, $body);
415 $result = $this->MailSend($header, $body);
417 //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
426 * Sends mail using the $Sendmail program.
430 function SendmailSend($header, $body) {
431 if ($this->Sender != '') {
432 $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
434 $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
437 if(!@$mail = popen($sendmail, 'w')) {
438 $this->SetError($this->Lang('execute') . $this->Sendmail);
442 fputs($mail, $header);
445 $result = pclose($mail);
446 if (version_compare(phpversion(), '4.2.3') == -1) {
447 $result = $result >> 8 & 0xFF;
450 $this->SetError($this->Lang('execute') . $this->Sendmail);
457 * Sends mail using the PHP mail() function.
461 function MailSend($header, $body) {
464 for($i = 0; $i < count($this->to); $i++) {
465 if($i != 0) { $to .= ', '; }
466 $to .= $this->AddrFormat($this->to[$i]);
469 $toArr = split(',', $to);
471 $params = sprintf("-oi -f %s", $this->Sender);
472 if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) {
473 $old_from = ini_get('sendmail_from');
474 ini_set('sendmail_from', $this->Sender);
475 if ($this->SingleTo === true && count($toArr) > 1) {
476 foreach ($toArr as $key => $val) {
477 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
480 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
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);
492 if (isset($old_from)) {
493 ini_set('sendmail_from', $old_from);
497 $this->SetError($this->Lang('instantiate'));
505 * Sends mail via SMTP using PhpSMTP (Author:
506 * Chris Ryan). Returns bool. Returns false if there is a
507 * bad MAIL FROM, RCPT, or DATA input.
511 function SmtpSend($header, $body) {
512 include_once($this->PluginDir . 'class.smtp.php');
516 if(!$this->SmtpConnect()) {
520 $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
521 if(!$this->smtp->Mail($smtp_from)) {
522 $error = $this->Lang('from_failed') . $smtp_from;
523 $this->SetError($error);
524 $this->smtp->Reset();
528 /* Attempt to send attach all recipients */
529 for($i = 0; $i < count($this->to); $i++) {
530 if(!$this->smtp->Recipient($this->to[$i][0])) {
531 $bad_rcpt[] = $this->to[$i][0];
534 for($i = 0; $i < count($this->cc); $i++) {
535 if(!$this->smtp->Recipient($this->cc[$i][0])) {
536 $bad_rcpt[] = $this->cc[$i][0];
539 for($i = 0; $i < count($this->bcc); $i++) {
540 if(!$this->smtp->Recipient($this->bcc[$i][0])) {
541 $bad_rcpt[] = $this->bcc[$i][0];
545 if(count($bad_rcpt) > 0) { // Create error message
546 for($i = 0; $i < count($bad_rcpt); $i++) {
550 $error .= $bad_rcpt[$i];
552 $error = $this->Lang('recipients_failed') . $error;
553 $this->SetError($error);
554 $this->smtp->Reset();
558 if(!$this->smtp->Data($header . $body)) {
559 $this->SetError($this->Lang('data_not_accepted'));
560 $this->smtp->Reset();
563 if($this->SMTPKeepAlive == true) {
564 $this->smtp->Reset();
573 * Initiates a connection to an SMTP server. Returns false if the
578 function SmtpConnect() {
579 if($this->smtp == NULL) {
580 $this->smtp = new SMTP();
583 $this->smtp->do_debug = $this->SMTPDebug;
584 $hosts = explode(';', $this->Host);
586 $connection = ($this->smtp->Connected());
588 /* Retry while there is no connection */
589 while($index < count($hosts) && $connection == false) {
591 if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
592 $host = $hostinfo[1];
593 $port = $hostinfo[2];
595 $host = $hosts[$index];
599 if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) {
600 if ($this->Helo != '') {
601 $this->smtp->Hello($this->Helo);
603 $this->smtp->Hello($this->ServerHostname());
607 if($this->SMTPAuth) {
608 if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
609 $this->SetError($this->Lang('authenticate'));
610 $this->smtp->Reset();
618 $this->SetError($this->Lang('connect_host'));
625 * Closes the active SMTP session if one exists.
628 function SmtpClose() {
629 if($this->smtp != NULL) {
630 if($this->smtp->Connected()) {
632 $this->smtp->Close();
638 * Sets the language for all class error messages. Returns false
639 * if it cannot load the language file. The default language type
641 * @param string $lang_type Type of language (e.g. Portuguese: "br")
642 * @param string $lang_path Path to the language file directory
646 function SetLanguage($lang_type, $lang_path = 'language/') {
647 if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
648 include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
649 } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) {
650 include($lang_path.'phpmailer.lang-en.php');
652 $this->SetError('Could not load language file');
655 $this->language = $PHPMAILER_LANG;
660 /////////////////////////////////////////////////
661 // METHODS, MESSAGE CREATION
662 /////////////////////////////////////////////////
665 * Creates recipient headers.
669 function AddrAppend($type, $addr) {
670 $addr_str = $type . ': ';
671 $addr_str .= $this->AddrFormat($addr[0]);
672 if(count($addr) > 1) {
673 for($i = 1; $i < count($addr); $i++) {
674 $addr_str .= ', ' . $this->AddrFormat($addr[$i]);
677 $addr_str .= $this->LE;
683 * Formats an address correctly.
687 function AddrFormat($addr) {
688 if(empty($addr[1])) {
689 $formatted = $this->SecureHeader($addr[0]);
691 $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
698 * Wraps message for use with mailers that do not
699 * automatically perform wrapping and for quoted-printable.
700 * Original written by philippe.
704 function WrapText($message, $length, $qp_mode = false) {
705 $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
706 // If utf-8 encoding is used, we will need to make sure we don't
707 // split multibyte characters when we wrap
708 $is_utf8 = (strtolower($this->CharSet) == "utf-8");
710 $message = $this->FixEOL($message);
711 if (substr($message, -1) == $this->LE) {
712 $message = substr($message, 0, -1);
715 $line = explode($this->LE, $message);
717 for ($i=0 ;$i < count($line); $i++) {
718 $line_part = explode(' ', $line[$i]);
720 for ($e = 0; $e<count($line_part); $e++) {
721 $word = $line_part[$e];
722 if ($qp_mode and (strlen($word) > $length)) {
723 $space_left = $length - strlen($buf) - 1;
725 if ($space_left > 20) {
728 $len = $this->UTF8CharBoundary($word, $len);
729 } elseif (substr($word, $len - 1, 1) == "=") {
731 } elseif (substr($word, $len - 2, 1) == "=") {
734 $part = substr($word, 0, $len);
735 $word = substr($word, $len);
737 $message .= $buf . sprintf("=%s", $this->LE);
739 $message .= $buf . $soft_break;
743 while (strlen($word) > 0) {
746 $len = $this->UTF8CharBoundary($word, $len);
747 } elseif (substr($word, $len - 1, 1) == "=") {
749 } elseif (substr($word, $len - 2, 1) == "=") {
752 $part = substr($word, 0, $len);
753 $word = substr($word, $len);
755 if (strlen($word) > 0) {
756 $message .= $part . sprintf("=%s", $this->LE);
763 $buf .= ($e == 0) ? $word : (' ' . $word);
765 if (strlen($buf) > $length and $buf_o != '') {
766 $message .= $buf_o . $soft_break;
771 $message .= $buf . $this->LE;
778 * Finds last character boundary prior to maxLength in a utf-8
779 * quoted (printable) encoded string.
780 * Original written by Colin Brown.
782 * @param string $encodedText utf-8 QP text
783 * @param int $maxLength find last character boundary prior to this length
786 function UTF8CharBoundary($encodedText, $maxLength) {
787 $foundSplitPos = false;
789 while (!$foundSplitPos) {
790 $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
791 $encodedCharPos = strpos($lastChunk, "=");
792 if ($encodedCharPos !== false) {
793 // Found start of encoded character byte within $lookBack block.
794 // Check the encoded byte value (the 2 chars after the '=')
795 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
797 if ($dec < 128) { // Single byte character.
798 // If the encoded char was found at pos 0, it will fit
799 // otherwise reduce maxLength to start of the encoded char
800 $maxLength = ($encodedCharPos == 0) ? $maxLength :
801 $maxLength - ($lookBack - $encodedCharPos);
802 $foundSplitPos = true;
803 } elseif ($dec >= 192) { // First byte of a multi byte character
804 // Reduce maxLength to split at start of character
805 $maxLength = $maxLength - ($lookBack - $encodedCharPos);
806 $foundSplitPos = true;
807 } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
811 // No encoded character found
812 $foundSplitPos = true;
819 * Set the body wrapping.
823 function SetWordWrap() {
824 if($this->WordWrap < 1) {
828 switch($this->message_type) {
831 case 'alt_attachments':
832 $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
835 $this->Body = $this->WrapText($this->Body, $this->WordWrap);
841 * Assembles message header.
845 function CreateHeader() {
848 /* Set the boundaries */
849 $uniq_id = md5(uniqid(time()));
850 $this->boundary[1] = 'b1_' . $uniq_id;
851 $this->boundary[2] = 'b2_' . $uniq_id;
853 $result .= $this->HeaderLine('Date', $this->RFCDate());
854 if($this->Sender == '') {
855 $result .= $this->HeaderLine('Return-Path', trim($this->From));
857 $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
860 /* To be created automatically by mail() */
861 if($this->Mailer != 'mail') {
862 if(count($this->to) > 0) {
863 $result .= $this->AddrAppend('To', $this->to);
864 } elseif (count($this->cc) == 0) {
865 $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
867 if(count($this->cc) > 0) {
868 $result .= $this->AddrAppend('Cc', $this->cc);
873 $from[0][0] = trim($this->From);
874 $from[0][1] = $this->FromName;
875 $result .= $this->AddrAppend('From', $from);
877 /* sendmail and mail() extract Cc from the header before sending */
878 if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
879 $result .= $this->AddrAppend('Cc', $this->cc);
882 /* sendmail and mail() extract Bcc from the header before sending */
883 if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
884 $result .= $this->AddrAppend('Bcc', $this->bcc);
887 if(count($this->ReplyTo) > 0) {
888 $result .= $this->AddrAppend('Reply-To', $this->ReplyTo);
891 /* mail() sets the subject itself */
892 if($this->Mailer != 'mail') {
893 $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
896 if($this->MessageID != '') {
897 $result .= $this->HeaderLine('Message-ID',$this->MessageID);
899 $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
901 $result .= $this->HeaderLine('X-Priority', $this->Priority);
902 $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']');
904 if($this->ConfirmReadingTo != '') {
905 $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
908 // Add custom headers
909 for($index = 0; $index < count($this->CustomHeader); $index++) {
910 $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
912 if (!$this->sign_key_file) {
913 $result .= $this->HeaderLine('MIME-Version', '1.0');
914 $result .= $this->GetMailMIME();
921 * Returns the message MIME.
925 function GetMailMIME() {
927 switch($this->message_type) {
929 $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
930 $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
934 case 'alt_attachments':
935 if($this->InlineImageExists()){
936 $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
938 $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
939 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
943 $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
944 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
948 if($this->Mailer != 'mail') {
949 $result .= $this->LE.$this->LE;
956 * Assembles the message body. Returns an empty string on failure.
960 function CreateBody() {
962 if ($this->sign_key_file) {
963 $result .= $this->GetMailMIME();
966 $this->SetWordWrap();
968 switch($this->message_type) {
970 $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
971 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
972 $result .= $this->LE.$this->LE;
973 $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
974 $result .= $this->EncodeString($this->Body, $this->Encoding);
975 $result .= $this->LE.$this->LE;
976 $result .= $this->EndBoundary($this->boundary[1]);
979 $result .= $this->EncodeString($this->Body, $this->Encoding);
982 $result .= $this->GetBoundary($this->boundary[1], '', '', '');
983 $result .= $this->EncodeString($this->Body, $this->Encoding);
984 $result .= $this->LE;
985 $result .= $this->AttachAll();
987 case 'alt_attachments':
988 $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
989 $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
990 $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
991 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
992 $result .= $this->LE.$this->LE;
993 $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
994 $result .= $this->EncodeString($this->Body, $this->Encoding);
995 $result .= $this->LE.$this->LE;
996 $result .= $this->EndBoundary($this->boundary[2]);
997 $result .= $this->AttachAll();
1001 if($this->IsError()) {
1003 } else if ($this->sign_key_file) {
1004 $file = tempnam("", "mail");
1005 $fp = fopen($file, "w");
1006 fwrite($fp, $result);
1008 $signed = tempnam("", "signed");
1010 if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_key_file, array("file://".$this->sign_key_file, $this->sign_key_pass), null)) {
1011 $fp = fopen($signed, "r");
1012 $result = fread($fp, filesize($this->sign_key_file));
1015 $this->SetError($this->Lang("signing").openssl_error_string());
1027 * Returns the start of a message boundary.
1030 function GetBoundary($boundary, $charSet, $contentType, $encoding) {
1032 if($charSet == '') {
1033 $charSet = $this->CharSet;
1035 if($contentType == '') {
1036 $contentType = $this->ContentType;
1038 if($encoding == '') {
1039 $encoding = $this->Encoding;
1041 $result .= $this->TextLine('--' . $boundary);
1042 $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
1043 $result .= $this->LE;
1044 $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
1045 $result .= $this->LE;
1051 * Returns the end of a message boundary.
1054 function EndBoundary($boundary) {
1055 return $this->LE . '--' . $boundary . '--' . $this->LE;
1059 * Sets the message type.
1063 function SetMessageType() {
1064 if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
1065 $this->message_type = 'plain';
1067 if(count($this->attachment) > 0) {
1068 $this->message_type = 'attachments';
1070 if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
1071 $this->message_type = 'alt';
1073 if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
1074 $this->message_type = 'alt_attachments';
1079 /* Returns a formatted header line.
1083 function HeaderLine($name, $value) {
1084 return $name . ': ' . $value . $this->LE;
1088 * Returns a formatted mail line.
1092 function TextLine($value) {
1093 return $value . $this->LE;
1096 /////////////////////////////////////////////////
1097 // CLASS METHODS, ATTACHMENTS
1098 /////////////////////////////////////////////////
1101 * Adds an attachment from a path on the filesystem.
1102 * Returns false if the file could not be found
1104 * @param string $path Path to the attachment.
1105 * @param string $name Overrides the attachment name.
1106 * @param string $encoding File encoding (see $Encoding).
1107 * @param string $type File extension (MIME) type.
1110 function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
1111 if(!@is_file($path)) {
1112 $this->SetError($this->Lang('file_access') . $path);
1116 $filename = basename($path);
1121 $cur = count($this->attachment);
1122 $this->attachment[$cur][0] = $path;
1123 $this->attachment[$cur][1] = $filename;
1124 $this->attachment[$cur][2] = $name;
1125 $this->attachment[$cur][3] = $encoding;
1126 $this->attachment[$cur][4] = $type;
1127 $this->attachment[$cur][5] = false; // isStringAttachment
1128 $this->attachment[$cur][6] = 'attachment';
1129 $this->attachment[$cur][7] = 0;
1135 * Attaches all fs, string, and binary attachments to the message.
1136 * Returns an empty string on failure.
1140 function AttachAll() {
1141 /* Return text of body */
1144 /* Add all attachments */
1145 for($i = 0; $i < count($this->attachment); $i++) {
1146 /* Check for string attachment */
1147 $bString = $this->attachment[$i][5];
1149 $string = $this->attachment[$i][0];
1151 $path = $this->attachment[$i][0];
1154 $filename = $this->attachment[$i][1];
1155 $name = $this->attachment[$i][2];
1156 $encoding = $this->attachment[$i][3];
1157 $type = $this->attachment[$i][4];
1158 $disposition = $this->attachment[$i][6];
1159 $cid = $this->attachment[$i][7];
1161 $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
1162 $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
1163 $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
1165 if($disposition == 'inline') {
1166 $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
1169 $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $name, $this->LE.$this->LE);
1171 /* Encode as string attachment */
1173 $mime[] = $this->EncodeString($string, $encoding);
1174 if($this->IsError()) {
1177 $mime[] = $this->LE.$this->LE;
1179 $mime[] = $this->EncodeFile($path, $encoding);
1180 if($this->IsError()) {
1183 $mime[] = $this->LE.$this->LE;
1187 $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
1189 return join('', $mime);
1193 * Encodes attachment in requested format. Returns an
1194 * empty string on failure.
1198 function EncodeFile ($path, $encoding = 'base64') {
1199 if(!@$fd = fopen($path, 'rb')) {
1200 $this->SetError($this->Lang('file_open') . $path);
1203 $magic_quotes = get_magic_quotes_runtime();
1204 set_magic_quotes_runtime(0);
1205 $file_buffer = fread($fd, filesize($path));
1206 $file_buffer = $this->EncodeString($file_buffer, $encoding);
1208 set_magic_quotes_runtime($magic_quotes);
1210 return $file_buffer;
1214 * Encodes string to requested format. Returns an
1215 * empty string on failure.
1219 function EncodeString ($str, $encoding = 'base64') {
1221 switch(strtolower($encoding)) {
1223 /* chunk_split is found in PHP >= 3.0.6 */
1224 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
1228 $encoded = $this->FixEOL($str);
1229 if (substr($encoded, -(strlen($this->LE))) != $this->LE)
1230 $encoded .= $this->LE;
1235 case 'quoted-printable':
1236 $encoded = $this->EncodeQP($str);
1239 $this->SetError($this->Lang('encoding') . $encoding);
1246 * Encode a header string to best of Q, B, quoted or none.
1250 function EncodeHeader ($str, $position = 'text') {
1253 switch (strtolower($position)) {
1255 if (!preg_match('/[\200-\377]/', $str)) {
1256 /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */
1257 $encoded = addcslashes($str, "\0..\37\177\\\"");
1258 if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
1261 return ("\"$encoded\"");
1264 $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
1267 $x = preg_match_all('/[()"]/', $str, $matches);
1271 $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
1279 $maxlen = 75 - 7 - strlen($this->CharSet);
1280 /* Try to select the encoding which should produce the shortest output */
1281 if (strlen($str)/3 < $x) {
1283 if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
1284 // Use a custom function which correctly encodes and wraps long
1285 // multibyte strings without breaking lines within a character
1286 $encoded = $this->Base64EncodeWrapMB($str);
1288 $encoded = base64_encode($str);
1289 $maxlen -= $maxlen % 4;
1290 $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
1294 $encoded = $this->EncodeQ($str, $position);
1295 $encoded = $this->WrapText($encoded, $maxlen, true);
1296 $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
1299 $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
1300 $encoded = trim(str_replace("\n", $this->LE, $encoded));
1306 * Checks if a string contains multibyte characters.
1308 * @param string $str multi-byte text to wrap encode
1311 function HasMultiBytes($str) {
1312 if (function_exists('mb_strlen')) {
1313 return (strlen($str) > mb_strlen($str, $this->CharSet));
1314 } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
1320 * Correctly encodes and wraps long multibyte strings for mail headers
1321 * without breaking lines within a character.
1322 * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
1324 * @param string $str multi-byte text to wrap encode
1327 function Base64EncodeWrapMB($str) {
1328 $start = "=?".$this->CharSet."?B?";
1332 $mb_length = mb_strlen($str, $this->CharSet);
1333 // Each line must have length <= 75, including $start and $end
1334 $length = 75 - strlen($start) - strlen($end);
1335 // Average multi-byte ratio
1336 $ratio = $mb_length / strlen($str);
1337 // Base64 has a 4:3 ratio
1338 $offset = $avgLength = floor($length * $ratio * .75);
1340 for ($i = 0; $i < $mb_length; $i += $offset) {
1344 $offset = $avgLength - $lookBack;
1345 $chunk = mb_substr($str, $i, $offset, $this->CharSet);
1346 $chunk = base64_encode($chunk);
1349 while (strlen($chunk) > $length);
1351 $encoded .= $chunk . $this->LE;
1354 // Chomp the last linefeed
1355 $encoded = substr($encoded, 0, -strlen($this->LE));
1360 * Encode string to quoted-printable.
1364 function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) {
1365 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
1366 $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
1370 while( list(, $line) = each($lines) ) {
1371 $linlen = strlen($line);
1373 for($i = 0; $i < $linlen; $i++) {
1374 $c = substr( $line, $i, 1 );
1376 if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
1380 if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
1382 } else if ( $space_conv ) {
1385 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
1386 $h2 = floor($dec/16);
1387 $h1 = floor($dec%16);
1388 $c = $escape.$hex[$h2].$hex[$h1];
1390 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
1391 $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
1393 // check if newline first character will be point or not
1400 $output .= $newline.$eol;
1402 return trim($output);
1406 * Encode string to q encoding.
1410 function EncodeQ ($str, $position = 'text') {
1411 /* There should not be any EOL in the string */
1412 $encoded = preg_replace("[\r\n]", '', $str);
1414 switch (strtolower($position)) {
1416 $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
1419 $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
1422 /* Replace every high ascii, control =, ? and _ characters */
1423 $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
1424 "'='.sprintf('%02X', ord('\\1'))", $encoded);
1428 /* Replace every spaces to _ (more readable than =20) */
1429 $encoded = str_replace(' ', '_', $encoded);
1435 * Adds a string or binary attachment (non-filesystem) to the list.
1436 * This method can be used to attach ascii or binary data,
1437 * such as a BLOB record from a database.
1438 * @param string $string String attachment data.
1439 * @param string $filename Name of the attachment.
1440 * @param string $encoding File encoding (see $Encoding).
1441 * @param string $type File extension (MIME) type.
1444 function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
1445 /* Append to $attachment array */
1446 $cur = count($this->attachment);
1447 $this->attachment[$cur][0] = $string;
1448 $this->attachment[$cur][1] = $filename;
1449 $this->attachment[$cur][2] = $filename;
1450 $this->attachment[$cur][3] = $encoding;
1451 $this->attachment[$cur][4] = $type;
1452 $this->attachment[$cur][5] = true; // isString
1453 $this->attachment[$cur][6] = 'attachment';
1454 $this->attachment[$cur][7] = 0;
1458 * Adds an embedded attachment. This can include images, sounds, and
1459 * just about any other document. Make sure to set the $type to an
1460 * image type. For JPEG images use "image/jpeg" and for GIF images
1462 * @param string $path Path to the attachment.
1463 * @param string $cid Content ID of the attachment. Use this to identify
1464 * the Id for accessing the image in an HTML form.
1465 * @param string $name Overrides the attachment name.
1466 * @param string $encoding File encoding (see $Encoding).
1467 * @param string $type File extension (MIME) type.
1470 function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
1472 if(!@is_file($path)) {
1473 $this->SetError($this->Lang('file_access') . $path);
1477 $filename = basename($path);
1482 /* Append to $attachment array */
1483 $cur = count($this->attachment);
1484 $this->attachment[$cur][0] = $path;
1485 $this->attachment[$cur][1] = $filename;
1486 $this->attachment[$cur][2] = $name;
1487 $this->attachment[$cur][3] = $encoding;
1488 $this->attachment[$cur][4] = $type;
1489 $this->attachment[$cur][5] = false;
1490 $this->attachment[$cur][6] = 'inline';
1491 $this->attachment[$cur][7] = $cid;
1497 * Returns true if an inline attachment is present.
1501 function InlineImageExists() {
1503 for($i = 0; $i < count($this->attachment); $i++) {
1504 if($this->attachment[$i][6] == 'inline') {
1513 /////////////////////////////////////////////////
1514 // CLASS METHODS, MESSAGE RESET
1515 /////////////////////////////////////////////////
1518 * Clears all recipients assigned in the TO array. Returns void.
1521 function ClearAddresses() {
1522 $this->to = array();
1526 * Clears all recipients assigned in the CC array. Returns void.
1529 function ClearCCs() {
1530 $this->cc = array();
1534 * Clears all recipients assigned in the BCC array. Returns void.
1537 function ClearBCCs() {
1538 $this->bcc = array();
1542 * Clears all recipients assigned in the ReplyTo array. Returns void.
1545 function ClearReplyTos() {
1546 $this->ReplyTo = array();
1550 * Clears all recipients assigned in the TO, CC and BCC
1551 * array. Returns void.
1554 function ClearAllRecipients() {
1555 $this->to = array();
1556 $this->cc = array();
1557 $this->bcc = array();
1561 * Clears all previously set filesystem, string, and binary
1562 * attachments. Returns void.
1565 function ClearAttachments() {
1566 $this->attachment = array();
1570 * Clears all custom headers. Returns void.
1573 function ClearCustomHeaders() {
1574 $this->CustomHeader = array();
1577 /////////////////////////////////////////////////
1578 // CLASS METHODS, MISCELLANEOUS
1579 /////////////////////////////////////////////////
1582 * Adds the error message to the error container.
1587 function SetError($msg) {
1588 $this->error_count++;
1589 $this->ErrorInfo = $msg;
1593 * Returns the proper RFC 822 formatted date.
1597 function RFCDate() {
1599 $tzs = ($tz < 0) ? '-' : '+';
1601 $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
1602 $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
1608 * Returns the appropriate server variable. Should work with both
1609 * PHP 4.1.0+ as well as older versions. Returns an empty string
1610 * if nothing is found.
1614 function ServerVar($varName) {
1615 global $HTTP_SERVER_VARS;
1616 global $HTTP_ENV_VARS;
1618 if(!isset($_SERVER)) {
1619 $_SERVER = $HTTP_SERVER_VARS;
1620 if(!isset($_SERVER['REMOTE_ADDR'])) {
1621 $_SERVER = $HTTP_ENV_VARS; // must be Apache
1625 if(isset($_SERVER[$varName])) {
1626 return $_SERVER[$varName];
1633 * Returns the server hostname or 'localhost.localdomain' if unknown.
1637 function ServerHostname() {
1638 if ($this->Hostname != '') {
1639 $result = $this->Hostname;
1640 } elseif ($this->ServerVar('SERVER_NAME') != '') {
1641 $result = $this->ServerVar('SERVER_NAME');
1643 $result = 'localhost.localdomain';
1650 * Returns a message in the appropriate language.
1654 function Lang($key) {
1655 if(count($this->language) < 1) {
1656 $this->SetLanguage('en'); // set the default language
1659 if(isset($this->language[$key])) {
1660 return $this->language[$key];
1662 return 'Language string failed to load: ' . $key;
1667 * Returns true if an error occurred.
1670 function IsError() {
1671 return ($this->error_count > 0);
1675 * Changes every end of line from CR or LF to CRLF.
1679 function FixEOL($str) {
1680 $str = str_replace("\r\n", "\n", $str);
1681 $str = str_replace("\r", "\n", $str);
1682 $str = str_replace("\n", $this->LE, $str);
1687 * Adds a custom header.
1690 function AddCustomHeader($custom_header) {
1691 $this->CustomHeader[] = explode(':', $custom_header, 2);
1695 * Evaluates the message and returns modifications for inline images and backgrounds
1699 function MsgHTML($message,$basedir='') {
1700 preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
1701 if(isset($images[2])) {
1702 foreach($images[2] as $i => $url) {
1703 // do not change urls for absolute images (thanks to corvuscorax)
1704 if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) {
1705 $filename = basename($url);
1706 $directory = dirname($url);
1707 ($directory == '.')?$directory='':'';
1708 $cid = 'cid:' . md5($filename);
1709 $fileParts = split("\.", $filename);
1710 $ext = $fileParts[1];
1711 $mimeType = $this->_mime_types($ext);
1712 if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
1713 if ( strlen($directory) > 1 && substr($basedir,-1) != '/') { $directory .= '/'; }
1714 $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType);
1715 if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
1716 $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
1721 $this->IsHTML(true);
1722 $this->Body = $message;
1723 $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
1724 if ( !empty($textMsg) && empty($this->AltBody) ) {
1725 $this->AltBody = $textMsg;
1727 if ( empty($this->AltBody) ) {
1728 $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";
1733 * Gets the mime type of the embedded or inline image
1735 * @return mime type of ext
1737 function _mime_types($ext = '') {
1739 'hqx' => 'application/mac-binhex40',
1740 'cpt' => 'application/mac-compactpro',
1741 'doc' => 'application/msword',
1742 'bin' => 'application/macbinary',
1743 'dms' => 'application/octet-stream',
1744 'lha' => 'application/octet-stream',
1745 'lzh' => 'application/octet-stream',
1746 'exe' => 'application/octet-stream',
1747 'class' => 'application/octet-stream',
1748 'psd' => 'application/octet-stream',
1749 'so' => 'application/octet-stream',
1750 'sea' => 'application/octet-stream',
1751 'dll' => 'application/octet-stream',
1752 'oda' => 'application/oda',
1753 'pdf' => 'application/pdf',
1754 'ai' => 'application/postscript',
1755 'eps' => 'application/postscript',
1756 'ps' => 'application/postscript',
1757 'smi' => 'application/smil',
1758 'smil' => 'application/smil',
1759 'mif' => 'application/vnd.mif',
1760 'xls' => 'application/vnd.ms-excel',
1761 'ppt' => 'application/vnd.ms-powerpoint',
1762 'wbxml' => 'application/vnd.wap.wbxml',
1763 'wmlc' => 'application/vnd.wap.wmlc',
1764 'dcr' => 'application/x-director',
1765 'dir' => 'application/x-director',
1766 'dxr' => 'application/x-director',
1767 'dvi' => 'application/x-dvi',
1768 'gtar' => 'application/x-gtar',
1769 'php' => 'application/x-httpd-php',
1770 'php4' => 'application/x-httpd-php',
1771 'php3' => 'application/x-httpd-php',
1772 'phtml' => 'application/x-httpd-php',
1773 'phps' => 'application/x-httpd-php-source',
1774 'js' => 'application/x-javascript',
1775 'swf' => 'application/x-shockwave-flash',
1776 'sit' => 'application/x-stuffit',
1777 'tar' => 'application/x-tar',
1778 'tgz' => 'application/x-tar',
1779 'xhtml' => 'application/xhtml+xml',
1780 'xht' => 'application/xhtml+xml',
1781 'zip' => 'application/zip',
1782 'mid' => 'audio/midi',
1783 'midi' => 'audio/midi',
1784 'mpga' => 'audio/mpeg',
1785 'mp2' => 'audio/mpeg',
1786 'mp3' => 'audio/mpeg',
1787 'aif' => 'audio/x-aiff',
1788 'aiff' => 'audio/x-aiff',
1789 'aifc' => 'audio/x-aiff',
1790 'ram' => 'audio/x-pn-realaudio',
1791 'rm' => 'audio/x-pn-realaudio',
1792 'rpm' => 'audio/x-pn-realaudio-plugin',
1793 'ra' => 'audio/x-realaudio',
1794 'rv' => 'video/vnd.rn-realvideo',
1795 'wav' => 'audio/x-wav',
1796 'bmp' => 'image/bmp',
1797 'gif' => 'image/gif',
1798 'jpeg' => 'image/jpeg',
1799 'jpg' => 'image/jpeg',
1800 'jpe' => 'image/jpeg',
1801 'png' => 'image/png',
1802 'tiff' => 'image/tiff',
1803 'tif' => 'image/tiff',
1804 'css' => 'text/css',
1805 'html' => 'text/html',
1806 'htm' => 'text/html',
1807 'shtml' => 'text/html',
1808 'txt' => 'text/plain',
1809 'text' => 'text/plain',
1810 'log' => 'text/plain',
1811 'rtx' => 'text/richtext',
1812 'rtf' => 'text/rtf',
1813 'xml' => 'text/xml',
1814 'xsl' => 'text/xml',
1815 'mpeg' => 'video/mpeg',
1816 'mpg' => 'video/mpeg',
1817 'mpe' => 'video/mpeg',
1818 'qt' => 'video/quicktime',
1819 'mov' => 'video/quicktime',
1820 'avi' => 'video/x-msvideo',
1821 'movie' => 'video/x-sgi-movie',
1822 'doc' => 'application/msword',
1823 'word' => 'application/msword',
1824 'xl' => 'application/excel',
1825 'eml' => 'message/rfc822'
1827 return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
1831 * Set (or reset) Class Objects (variables)
1834 * $page->set('X-Priority', '3');
1837 * @param string $name Parameter Name
1838 * @param mixed $value Parameter Value
1839 * NOTE: will not work with arrays, there are no arrays to set/reset
1841 function set ( $name, $value = '' ) {
1842 if ( isset($this->$name) ) {
1843 $this->$name = $value;
1845 $this->SetError('Cannot set or reset variable ' . $name);
1851 * Read a file from a supplied filename and return it.
1854 * @param string $filename Parameter File Name
1856 function getFile($filename) {
1858 if ($fp = fopen($filename, 'rb')) {
1859 while (!feof($fp)) {
1860 $return .= fread($fp, 1024);
1870 * Strips newlines to prevent header injection.
1872 * @param string $str String
1875 function SecureHeader($str) {
1877 $str = str_replace("\r", "", $str);
1878 $str = str_replace("\n", "", $str);
1883 * Set the private key file and password to sign the message.
1886 * @param string $key_filename Parameter File Name
1887 * @param string $key_pass Password for private key
1889 function Sign($key_filename, $key_pass) {
1890 $this->sign_key_file = $key_filename;
1891 $this->sign_key_pass = $key_pass;