root@9: exceptions = ($exceptions == true); root@9: } root@9: root@9: /** root@9: * Sets message type to HTML. root@9: * @param bool $ishtml root@9: * @return void root@9: */ root@9: public function IsHTML($ishtml = true) { root@9: if ($ishtml) { root@9: $this->ContentType = 'text/html'; root@9: } else { root@9: $this->ContentType = 'text/plain'; root@9: } root@9: } root@9: root@9: /** root@9: * Sets Mailer to send message using SMTP. root@9: * @return void root@9: */ root@9: public function IsSMTP() { root@9: $this->Mailer = 'smtp'; root@9: } root@9: root@9: /** root@9: * Sets Mailer to send message using PHP mail() function. root@9: * @return void root@9: */ root@9: public function IsMail() { root@9: $this->Mailer = 'mail'; root@9: } root@9: root@9: /** root@9: * Sets Mailer to send message using the $Sendmail program. root@9: * @return void root@9: */ root@9: public function IsSendmail() { root@9: if (!stristr(ini_get('sendmail_path'), 'sendmail')) { root@9: $this->Sendmail = '/var/qmail/bin/sendmail'; root@9: } root@9: $this->Mailer = 'sendmail'; root@9: } root@9: root@9: /** root@9: * Sets Mailer to send message using the qmail MTA. root@9: * @return void root@9: */ root@9: public function IsQmail() { root@9: if (stristr(ini_get('sendmail_path'), 'qmail')) { root@9: $this->Sendmail = '/var/qmail/bin/sendmail'; root@9: } root@9: $this->Mailer = 'sendmail'; root@9: } root@9: root@9: ///////////////////////////////////////////////// root@9: // METHODS, RECIPIENTS root@9: ///////////////////////////////////////////////// root@9: root@9: /** root@9: * Adds a "To" address. root@9: * @param string $address root@9: * @param string $name root@9: * @return boolean true on success, false if address already used root@9: */ root@9: public function AddAddress($address, $name = '') { root@9: return $this->AddAnAddress('to', $address, $name); root@9: } root@9: root@9: /** root@9: * Adds a "Cc" address. root@9: * Note: this function works with the SMTP mailer on win32, not with the "mail" mailer. root@9: * @param string $address root@9: * @param string $name root@9: * @return boolean true on success, false if address already used root@9: */ root@9: public function AddCC($address, $name = '') { root@9: return $this->AddAnAddress('cc', $address, $name); root@9: } root@9: root@9: /** root@9: * Adds a "Bcc" address. root@9: * Note: this function works with the SMTP mailer on win32, not with the "mail" mailer. root@9: * @param string $address root@9: * @param string $name root@9: * @return boolean true on success, false if address already used root@9: */ root@9: public function AddBCC($address, $name = '') { root@9: return $this->AddAnAddress('bcc', $address, $name); root@9: } root@9: root@9: /** root@9: * Adds a "Reply-to" address. root@9: * @param string $address root@9: * @param string $name root@9: * @return boolean root@9: */ root@9: public function AddReplyTo($address, $name = '') { root@9: return $this->AddAnAddress('ReplyTo', $address, $name); root@9: } root@9: root@9: /** root@9: * Adds an address to one of the recipient arrays root@9: * Addresses that have been added already return false, but do not throw exceptions root@9: * @param string $kind One of 'to', 'cc', 'bcc', 'ReplyTo' root@9: * @param string $address The email address to send to root@9: * @param string $name root@9: * @return boolean true on success, false if address already used or invalid in some way root@9: * @access private root@9: */ root@9: private function AddAnAddress($kind, $address, $name = '') { root@9: if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) { root@9: echo 'Invalid recipient array: ' . kind; root@9: return false; root@9: } root@9: $address = trim($address); root@9: $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim root@9: if (!self::ValidateAddress($address)) { root@9: $this->SetError($this->Lang('invalid_address').': '. $address); root@9: if ($this->exceptions) { root@9: throw new phpmailerException($this->Lang('invalid_address').': '.$address); root@9: } root@9: echo $this->Lang('invalid_address').': '.$address; root@9: return false; root@9: } root@9: if ($kind != 'ReplyTo') { root@9: if (!isset($this->all_recipients[strtolower($address)])) { root@9: array_push($this->$kind, array($address, $name)); root@9: $this->all_recipients[strtolower($address)] = true; root@9: return true; root@9: } root@9: } else { root@9: if (!array_key_exists(strtolower($address), $this->ReplyTo)) { root@9: $this->ReplyTo[strtolower($address)] = array($address, $name); root@9: return true; root@9: } root@9: } root@9: return false; root@9: } root@9: root@9: /** root@9: * Set the From and FromName properties root@9: * @param string $address root@9: * @param string $name root@9: * @return boolean root@9: */ root@9: public function SetFrom($address, $name = '',$auto=1) { root@9: $address = trim($address); root@9: $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim root@9: if (!self::ValidateAddress($address)) { root@9: $this->SetError($this->Lang('invalid_address').': '. $address); root@9: if ($this->exceptions) { root@9: throw new phpmailerException($this->Lang('invalid_address').': '.$address); root@9: } root@9: echo $this->Lang('invalid_address').': '.$address; root@9: return false; root@9: } root@9: $this->From = $address; root@9: $this->FromName = $name; root@9: if ($auto) { root@9: if (empty($this->ReplyTo)) { root@9: $this->AddAnAddress('ReplyTo', $address, $name); root@9: } root@9: if (empty($this->Sender)) { root@9: $this->Sender = $address; root@9: } root@9: } root@9: return true; root@9: } root@9: root@9: /** root@9: * Check that a string looks roughly like an email address should root@9: * Static so it can be used without instantiation root@9: * Tries to use PHP built-in validator in the filter extension (from PHP 5.2), falls back to a reasonably competent regex validator root@9: * Conforms approximately to RFC2822 root@9: * @link http://www.hexillion.com/samples/#Regex Original pattern found here root@9: * @param string $address The email address to check root@9: * @return boolean root@9: * @static root@9: * @access public root@9: */ root@9: public static function ValidateAddress($address) { root@9: if (function_exists('filter_var')) { //Introduced in PHP 5.2 root@9: if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) { root@9: return false; root@9: } else { root@9: return true; root@9: } root@9: } else { root@9: return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address); root@9: } root@9: } root@9: root@9: ///////////////////////////////////////////////// root@9: // METHODS, MAIL SENDING root@9: ///////////////////////////////////////////////// root@9: root@9: /** root@9: * Creates message and assigns Mailer. If the message is root@9: * not sent successfully then it returns false. Use the ErrorInfo root@9: * variable to view description of the error. root@9: * @return bool root@9: */ root@9: public function Send() { root@9: try { root@9: if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { root@9: throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL); root@9: } root@9: root@9: // Set whether the message is multipart/alternative root@9: if(!empty($this->AltBody)) { root@9: $this->ContentType = 'multipart/alternative'; root@9: } root@9: root@9: $this->error_count = 0; // reset errors root@9: $this->SetMessageType(); root@9: $header = $this->CreateHeader(); root@9: $body = $this->CreateBody(); root@9: root@9: if (empty($this->Body)) { root@9: throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL); root@9: } root@9: root@9: // digitally sign with DKIM if enabled root@9: if ($this->DKIM_domain && $this->DKIM_private) { root@9: $header_dkim = $this->DKIM_Add($header,$this->Subject,$body); root@9: $header = str_replace("\r\n","\n",$header_dkim) . $header; root@9: } root@9: root@9: // Choose the mailer and send through it root@9: switch($this->Mailer) { root@9: case 'sendmail': root@9: return $this->SendmailSend($header, $body); root@9: case 'smtp': root@9: return $this->SmtpSend($header, $body); root@9: default: root@9: return $this->MailSend($header, $body); root@9: } root@9: root@9: } catch (phpmailerException $e) { root@9: $this->SetError($e->getMessage()); root@9: if ($this->exceptions) { root@9: throw $e; root@9: } root@9: echo $e->getMessage()."\n"; root@9: return false; root@9: } root@9: } root@9: root@9: /** root@9: * Sends mail using the $Sendmail program. root@9: * @param string $header The message headers root@9: * @param string $body The message body root@9: * @access protected root@9: * @return bool root@9: */ root@9: protected function SendmailSend($header, $body) { root@9: if ($this->Sender != '') { root@9: $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender)); root@9: } else { root@9: $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail)); root@9: } root@9: if ($this->SingleTo === true) { root@9: foreach ($this->SingleToArray as $key => $val) { root@9: if(!@$mail = popen($sendmail, 'w')) { root@9: throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); root@9: } root@9: fputs($mail, "To: " . $val . "\n"); root@9: fputs($mail, $header); root@9: fputs($mail, $body); root@9: $result = pclose($mail); root@9: // implement call back function if it exists root@9: $isSent = ($result == 0) ? 1 : 0; root@9: $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); root@9: if($result != 0) { root@9: throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); root@9: } root@9: } root@9: } else { root@9: if(!@$mail = popen($sendmail, 'w')) { root@9: throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); root@9: } root@9: fputs($mail, $header); root@9: fputs($mail, $body); root@9: $result = pclose($mail); root@9: // implement call back function if it exists root@9: $isSent = ($result == 0) ? 1 : 0; root@9: $this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body); root@9: if($result != 0) { root@9: throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); root@9: } root@9: } root@9: return true; root@9: } root@9: root@9: /** root@9: * Sends mail using the PHP mail() function. root@9: * @param string $header The message headers root@9: * @param string $body The message body root@9: * @access protected root@9: * @return bool root@9: */ root@9: protected function MailSend($header, $body) { root@9: $toArr = array(); root@9: foreach($this->to as $t) { root@9: $toArr[] = $this->AddrFormat($t); root@9: } root@9: $to = implode(', ', $toArr); root@9: root@9: $params = sprintf("-oi -f %s", $this->Sender); root@9: if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) { root@9: $old_from = ini_get('sendmail_from'); root@9: ini_set('sendmail_from', $this->Sender); root@9: if ($this->SingleTo === true && count($toArr) > 1) { root@9: foreach ($toArr as $key => $val) { root@9: $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); root@9: // implement call back function if it exists root@9: $isSent = ($rt == 1) ? 1 : 0; root@9: $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); root@9: } root@9: } else { root@9: $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); root@9: // implement call back function if it exists root@9: $isSent = ($rt == 1) ? 1 : 0; root@9: $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body); root@9: } root@9: } else { root@9: if ($this->SingleTo === true && count($toArr) > 1) { root@9: foreach ($toArr as $key => $val) { root@9: $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); root@9: // implement call back function if it exists root@9: $isSent = ($rt == 1) ? 1 : 0; root@9: $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); root@9: } root@9: } else { root@9: $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header); root@9: // implement call back function if it exists root@9: $isSent = ($rt == 1) ? 1 : 0; root@9: $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body); root@9: } root@9: } root@9: if (isset($old_from)) { root@9: ini_set('sendmail_from', $old_from); root@9: } root@9: if(!$rt) { root@9: throw new phpmailerException($this->Lang('instantiate'), self::STOP_CRITICAL); root@9: } root@9: return true; root@9: } root@9: root@9: /** root@9: * Sends mail via SMTP using PhpSMTP root@9: * Returns false if there is a bad MAIL FROM, RCPT, or DATA input. root@9: * @param string $header The message headers root@9: * @param string $body The message body root@9: * @uses SMTP root@9: * @access protected root@9: * @return bool root@9: */ root@9: protected function SmtpSend($header, $body) { root@9: require_once $this->PluginDir . 'class.smtp.php'; root@9: $bad_rcpt = array(); root@9: root@9: if(!$this->SmtpConnect()) { root@9: throw new phpmailerException($this->Lang('smtp_connect_failed'), self::STOP_CRITICAL); root@9: } root@9: $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender; root@9: if(!$this->smtp->Mail($smtp_from)) { root@9: throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL); root@9: } root@9: root@9: // Attempt to send attach all recipients root@9: foreach($this->to as $to) { root@9: if (!$this->smtp->Recipient($to[0])) { root@9: $bad_rcpt[] = $to[0]; root@9: // implement call back function if it exists root@9: $isSent = 0; root@9: $this->doCallback($isSent,$to[0],'','',$this->Subject,$body); root@9: } else { root@9: // implement call back function if it exists root@9: $isSent = 1; root@9: $this->doCallback($isSent,$to[0],'','',$this->Subject,$body); root@9: } root@9: } root@9: foreach($this->cc as $cc) { root@9: if (!$this->smtp->Recipient($cc[0])) { root@9: $bad_rcpt[] = $cc[0]; root@9: // implement call back function if it exists root@9: $isSent = 0; root@9: $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body); root@9: } else { root@9: // implement call back function if it exists root@9: $isSent = 1; root@9: $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body); root@9: } root@9: } root@9: foreach($this->bcc as $bcc) { root@9: if (!$this->smtp->Recipient($bcc[0])) { root@9: $bad_rcpt[] = $bcc[0]; root@9: // implement call back function if it exists root@9: $isSent = 0; root@9: $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body); root@9: } else { root@9: // implement call back function if it exists root@9: $isSent = 1; root@9: $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body); root@9: } root@9: } root@9: root@9: root@9: if (count($bad_rcpt) > 0 ) { //Create error message for any bad addresses root@9: $badaddresses = implode(', ', $bad_rcpt); root@9: throw new phpmailerException($this->Lang('recipients_failed') . $badaddresses); root@9: } root@9: if(!$this->smtp->Data($header . $body)) { root@9: throw new phpmailerException($this->Lang('data_not_accepted'), self::STOP_CRITICAL); root@9: } root@9: if($this->SMTPKeepAlive == true) { root@9: $this->smtp->Reset(); root@9: } root@9: return true; root@9: } root@9: root@9: /** root@9: * Initiates a connection to an SMTP server. root@9: * Returns false if the operation failed. root@9: * @uses SMTP root@9: * @access public root@9: * @return bool root@9: */ root@9: public function SmtpConnect() { root@9: if(is_null($this->smtp)) { root@9: $this->smtp = new SMTP(); root@9: } root@9: root@9: $this->smtp->do_debug = $this->SMTPDebug; root@9: $hosts = explode(';', $this->Host); root@9: $index = 0; root@9: $connection = $this->smtp->Connected(); root@9: root@9: // Retry while there is no connection root@9: try { root@9: while($index < count($hosts) && !$connection) { root@9: $hostinfo = array(); root@9: if (preg_match('/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) { root@9: $host = $hostinfo[1]; root@9: $port = $hostinfo[2]; root@9: } else { root@9: $host = $hosts[$index]; root@9: $port = $this->Port; root@9: } root@9: root@9: $tls = ($this->SMTPSecure == 'tls'); root@9: $ssl = ($this->SMTPSecure == 'ssl'); root@9: root@9: if ($this->smtp->Connect(($ssl ? 'ssl://':'').$host, $port, $this->Timeout)) { root@9: root@9: $hello = ($this->Helo != '' ? $this->Helo : $this->ServerHostname()); root@9: $this->smtp->Hello($hello); root@9: root@9: if ($tls) { root@9: if (!$this->smtp->StartTLS()) { root@9: throw new phpmailerException($this->Lang('tls')); root@9: } root@9: root@9: //We must resend HELO after tls negotiation root@9: $this->smtp->Hello($hello); root@9: } root@9: root@9: $connection = true; root@9: if ($this->SMTPAuth) { root@9: if (!$this->smtp->Authenticate($this->Username, $this->Password)) { root@9: throw new phpmailerException($this->Lang('authenticate')); root@9: } root@9: } root@9: } root@9: $index++; root@9: if (!$connection) { root@9: throw new phpmailerException($this->Lang('connect_host')); root@9: } root@9: } root@9: } catch (phpmailerException $e) { root@9: $this->smtp->Reset(); root@9: throw $e; root@9: } root@9: return true; root@9: } root@9: root@9: /** root@9: * Closes the active SMTP session if one exists. root@9: * @return void root@9: */ root@9: public function SmtpClose() { root@9: if(!is_null($this->smtp)) { root@9: if($this->smtp->Connected()) { root@9: $this->smtp->Quit(); root@9: $this->smtp->Close(); root@9: } root@9: } root@9: } root@9: root@9: /** root@9: * Sets the language for all class error messages. root@9: * Returns false if it cannot load the language file. The default language is English. root@9: * @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br") root@9: * @param string $lang_path Path to the language file directory root@9: * @access public root@9: */ root@9: function SetLanguage($langcode = 'en', $lang_path = 'language/') { root@9: //Define full set of translatable strings root@9: $PHPMAILER_LANG = array( root@9: 'provide_address' => 'You must provide at least one recipient email address.', root@9: 'mailer_not_supported' => ' mailer is not supported.', root@9: 'execute' => 'Could not execute: ', root@9: 'instantiate' => 'Could not instantiate mail function.', root@9: 'authenticate' => 'SMTP Error: Could not authenticate.', root@9: 'from_failed' => 'The following From address failed: ', root@9: 'recipients_failed' => 'SMTP Error: The following recipients failed: ', root@9: 'data_not_accepted' => 'SMTP Error: Data not accepted.', root@9: 'connect_host' => 'SMTP Error: Could not connect to SMTP host.', root@9: 'file_access' => 'Could not access file: ', root@9: 'file_open' => 'File Error: Could not open file: ', root@9: 'encoding' => 'Unknown encoding: ', root@9: 'signing' => 'Signing Error: ', root@9: 'smtp_error' => 'SMTP server error: ', root@9: 'empty_message' => 'Message body empty', root@9: 'invalid_address' => 'Invalid address', root@9: 'variable_set' => 'Cannot set or reset variable: ' root@9: ); root@9: //Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"! root@9: $l = true; root@9: if ($langcode != 'en') { //There is no English translation file root@9: $l = @include $lang_path.'phpmailer.lang-'.$langcode.'.php'; root@9: } root@9: $this->language = $PHPMAILER_LANG; root@9: return ($l == true); //Returns false if language not found root@9: } root@9: root@9: /** root@9: * Return the current array of language strings root@9: * @return array root@9: */ root@9: public function GetTranslations() { root@9: return $this->language; root@9: } root@9: root@9: ///////////////////////////////////////////////// root@9: // METHODS, MESSAGE CREATION root@9: ///////////////////////////////////////////////// root@9: root@9: /** root@9: * Creates recipient headers. root@9: * @access public root@9: * @return string root@9: */ root@9: public function AddrAppend($type, $addr) { root@9: $addr_str = $type . ': '; root@9: $addresses = array(); root@9: foreach ($addr as $a) { root@9: $addresses[] = $this->AddrFormat($a); root@9: } root@9: $addr_str .= implode(', ', $addresses); root@9: $addr_str .= $this->LE; root@9: root@9: return $addr_str; root@9: } root@9: root@9: /** root@9: * Formats an address correctly. root@9: * @access public root@9: * @return string root@9: */ root@9: public function AddrFormat($addr) { root@9: if (empty($addr[1])) { root@9: return $this->SecureHeader($addr[0]); root@9: } else { root@9: return $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">"; root@9: } root@9: } root@9: root@9: /** root@9: * Wraps message for use with mailers that do not root@9: * automatically perform wrapping and for quoted-printable. root@9: * Original written by philippe. root@9: * @param string $message The message to wrap root@9: * @param integer $length The line length to wrap to root@9: * @param boolean $qp_mode Whether to run in Quoted-Printable mode root@9: * @access public root@9: * @return string root@9: */ root@9: public function WrapText($message, $length, $qp_mode = false) { root@9: $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE; root@9: // If utf-8 encoding is used, we will need to make sure we don't root@9: // split multibyte characters when we wrap root@9: $is_utf8 = (strtolower($this->CharSet) == "utf-8"); root@9: root@9: $message = $this->FixEOL($message); root@9: if (substr($message, -1) == $this->LE) { root@9: $message = substr($message, 0, -1); root@9: } root@9: root@9: $line = explode($this->LE, $message); root@9: $message = ''; root@9: for ($i=0 ;$i < count($line); $i++) { root@9: $line_part = explode(' ', $line[$i]); root@9: $buf = ''; root@9: for ($e = 0; $e $length)) { root@9: $space_left = $length - strlen($buf) - 1; root@9: if ($e != 0) { root@9: if ($space_left > 20) { root@9: $len = $space_left; root@9: if ($is_utf8) { root@9: $len = $this->UTF8CharBoundary($word, $len); root@9: } elseif (substr($word, $len - 1, 1) == "=") { root@9: $len--; root@9: } elseif (substr($word, $len - 2, 1) == "=") { root@9: $len -= 2; root@9: } root@9: $part = substr($word, 0, $len); root@9: $word = substr($word, $len); root@9: $buf .= ' ' . $part; root@9: $message .= $buf . sprintf("=%s", $this->LE); root@9: } else { root@9: $message .= $buf . $soft_break; root@9: } root@9: $buf = ''; root@9: } root@9: while (strlen($word) > 0) { root@9: $len = $length; root@9: if ($is_utf8) { root@9: $len = $this->UTF8CharBoundary($word, $len); root@9: } elseif (substr($word, $len - 1, 1) == "=") { root@9: $len--; root@9: } elseif (substr($word, $len - 2, 1) == "=") { root@9: $len -= 2; root@9: } root@9: $part = substr($word, 0, $len); root@9: $word = substr($word, $len); root@9: root@9: if (strlen($word) > 0) { root@9: $message .= $part . sprintf("=%s", $this->LE); root@9: } else { root@9: $buf = $part; root@9: } root@9: } root@9: } else { root@9: $buf_o = $buf; root@9: $buf .= ($e == 0) ? $word : (' ' . $word); root@9: root@9: if (strlen($buf) > $length and $buf_o != '') { root@9: $message .= $buf_o . $soft_break; root@9: $buf = $word; root@9: } root@9: } root@9: } root@9: $message .= $buf . $this->LE; root@9: } root@9: root@9: return $message; root@9: } root@9: root@9: /** root@9: * Finds last character boundary prior to maxLength in a utf-8 root@9: * quoted (printable) encoded string. root@9: * Original written by Colin Brown. root@9: * @access public root@9: * @param string $encodedText utf-8 QP text root@9: * @param int $maxLength find last character boundary prior to this length root@9: * @return int root@9: */ root@9: public function UTF8CharBoundary($encodedText, $maxLength) { root@9: $foundSplitPos = false; root@9: $lookBack = 3; root@9: while (!$foundSplitPos) { root@9: $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack); root@9: $encodedCharPos = strpos($lastChunk, "="); root@9: if ($encodedCharPos !== false) { root@9: // Found start of encoded character byte within $lookBack block. root@9: // Check the encoded byte value (the 2 chars after the '=') root@9: $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2); root@9: $dec = hexdec($hex); root@9: if ($dec < 128) { // Single byte character. root@9: // If the encoded char was found at pos 0, it will fit root@9: // otherwise reduce maxLength to start of the encoded char root@9: $maxLength = ($encodedCharPos == 0) ? $maxLength : root@9: $maxLength - ($lookBack - $encodedCharPos); root@9: $foundSplitPos = true; root@9: } elseif ($dec >= 192) { // First byte of a multi byte character root@9: // Reduce maxLength to split at start of character root@9: $maxLength = $maxLength - ($lookBack - $encodedCharPos); root@9: $foundSplitPos = true; root@9: } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back root@9: $lookBack += 3; root@9: } root@9: } else { root@9: // No encoded character found root@9: $foundSplitPos = true; root@9: } root@9: } root@9: return $maxLength; root@9: } root@9: root@9: root@9: /** root@9: * Set the body wrapping. root@9: * @access public root@9: * @return void root@9: */ root@9: public function SetWordWrap() { root@9: if($this->WordWrap < 1) { root@9: return; root@9: } root@9: root@9: switch($this->message_type) { root@9: case 'alt': root@9: case 'alt_attachments': root@9: $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); root@9: break; root@9: default: root@9: $this->Body = $this->WrapText($this->Body, $this->WordWrap); root@9: break; root@9: } root@9: } root@9: root@9: /** root@9: * Assembles message header. root@9: * @access public root@9: * @return string The assembled header root@9: */ root@9: public function CreateHeader() { root@9: $result = ''; root@9: root@9: // Set the boundaries root@9: $uniq_id = md5(uniqid(time())); root@9: $this->boundary[1] = 'b1_' . $uniq_id; root@9: $this->boundary[2] = 'b2_' . $uniq_id; root@9: root@9: $result .= $this->HeaderLine('Date', self::RFCDate()); root@9: if($this->Sender == '') { root@9: $result .= $this->HeaderLine('Return-Path', trim($this->From)); root@9: } else { root@9: $result .= $this->HeaderLine('Return-Path', trim($this->Sender)); root@9: } root@9: root@9: // To be created automatically by mail() root@9: if($this->Mailer != 'mail') { root@9: if ($this->SingleTo === true) { root@9: foreach($this->to as $t) { root@9: $this->SingleToArray[] = $this->AddrFormat($t); root@9: } root@9: } else { root@9: if(count($this->to) > 0) { root@9: $result .= $this->AddrAppend('To', $this->to); root@9: } elseif (count($this->cc) == 0) { root@9: $result .= $this->HeaderLine('To', 'undisclosed-recipients:;'); root@9: } root@9: } root@9: } root@9: root@9: $from = array(); root@9: $from[0][0] = trim($this->From); root@9: $from[0][1] = $this->FromName; root@9: $result .= $this->AddrAppend('From', $from); root@9: root@9: // sendmail and mail() extract Cc from the header before sending root@9: if(count($this->cc) > 0) { root@9: $result .= $this->AddrAppend('Cc', $this->cc); root@9: } root@9: root@9: // sendmail and mail() extract Bcc from the header before sending root@9: if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) { root@9: $result .= $this->AddrAppend('Bcc', $this->bcc); root@9: } root@9: root@9: if(count($this->ReplyTo) > 0) { root@9: $result .= $this->AddrAppend('Reply-to', $this->ReplyTo); root@9: } root@9: root@9: // mail() sets the subject itself root@9: if($this->Mailer != 'mail') { root@9: $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject))); root@9: } root@9: root@9: if($this->MessageID != '') { root@9: $result .= $this->HeaderLine('Message-ID',$this->MessageID); root@9: } else { root@9: $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); root@9: } root@9: $result .= $this->HeaderLine('X-Priority', $this->Priority); root@9: $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (phpmailer.sourceforge.net)'); root@9: root@9: if($this->ConfirmReadingTo != '') { root@9: $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>'); root@9: } root@9: root@9: // Add custom headers root@9: for($index = 0; $index < count($this->CustomHeader); $index++) { root@9: $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1]))); root@9: } root@9: if (!$this->sign_key_file) { root@9: $result .= $this->HeaderLine('MIME-Version', '1.0'); root@9: $result .= $this->GetMailMIME(); root@9: } root@9: root@9: return $result; root@9: } root@9: root@9: /** root@9: * Returns the message MIME. root@9: * @access public root@9: * @return string root@9: */ root@9: public function GetMailMIME() { root@9: $result = ''; root@9: switch($this->message_type) { root@9: case 'plain': root@9: $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); root@9: $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet); root@9: break; root@9: case 'attachments': root@9: case 'alt_attachments': root@9: if($this->InlineImageExists()){ root@9: $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE); root@9: } else { root@9: $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;'); root@9: $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); root@9: } root@9: break; root@9: case 'alt': root@9: $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); root@9: $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); root@9: break; root@9: } root@9: root@9: if($this->Mailer != 'mail') { root@9: $result .= $this->LE.$this->LE; root@9: } root@9: root@9: return $result; root@9: } root@9: root@9: /** root@9: * Assembles the message body. Returns an empty string on failure. root@9: * @access public root@9: * @return string The assembled message body root@9: */ root@9: public function CreateBody() { root@9: $body = ''; root@9: root@9: if ($this->sign_key_file) { root@9: $body .= $this->GetMailMIME(); root@9: } root@9: root@9: $this->SetWordWrap(); root@9: root@9: switch($this->message_type) { root@9: case 'alt': root@9: $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); root@9: $body .= $this->EncodeString($this->AltBody, $this->Encoding); root@9: $body .= $this->LE.$this->LE; root@9: $body .= $this->GetBoundary($this->boundary[1], '', 'text/html', ''); root@9: $body .= $this->EncodeString($this->Body, $this->Encoding); root@9: $body .= $this->LE.$this->LE; root@9: $body .= $this->EndBoundary($this->boundary[1]); root@9: break; root@9: case 'plain': root@9: $body .= $this->EncodeString($this->Body, $this->Encoding); root@9: break; root@9: case 'attachments': root@9: $body .= $this->GetBoundary($this->boundary[1], '', '', ''); root@9: $body .= $this->EncodeString($this->Body, $this->Encoding); root@9: $body .= $this->LE; root@9: $body .= $this->AttachAll(); root@9: break; root@9: case 'alt_attachments': root@9: $body .= sprintf("--%s%s", $this->boundary[1], $this->LE); root@9: $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE); root@9: $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body root@9: $body .= $this->EncodeString($this->AltBody, $this->Encoding); root@9: $body .= $this->LE.$this->LE; root@9: $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body root@9: $body .= $this->EncodeString($this->Body, $this->Encoding); root@9: $body .= $this->LE.$this->LE; root@9: $body .= $this->EndBoundary($this->boundary[2]); root@9: $body .= $this->AttachAll(); root@9: break; root@9: } root@9: root@9: if ($this->IsError()) { root@9: $body = ''; root@9: } elseif ($this->sign_key_file) { root@9: try { root@9: $file = tempnam('', 'mail'); root@9: file_put_contents($file, $body); //TODO check this worked root@9: $signed = tempnam("", "signed"); root@9: if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), NULL)) { root@9: @unlink($file); root@9: @unlink($signed); root@9: $body = file_get_contents($signed); root@9: } else { root@9: @unlink($file); root@9: @unlink($signed); root@9: throw new phpmailerException($this->Lang("signing").openssl_error_string()); root@9: } root@9: } catch (phpmailerException $e) { root@9: $body = ''; root@9: if ($this->exceptions) { root@9: throw $e; root@9: } root@9: } root@9: } root@9: root@9: return $body; root@9: } root@9: root@9: /** root@9: * Returns the start of a message boundary. root@9: * @access private root@9: */ root@9: private function GetBoundary($boundary, $charSet, $contentType, $encoding) { root@9: $result = ''; root@9: if($charSet == '') { root@9: $charSet = $this->CharSet; root@9: } root@9: if($contentType == '') { root@9: $contentType = $this->ContentType; root@9: } root@9: if($encoding == '') { root@9: $encoding = $this->Encoding; root@9: } root@9: $result .= $this->TextLine('--' . $boundary); root@9: $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet); root@9: $result .= $this->LE; root@9: $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding); root@9: $result .= $this->LE; root@9: root@9: return $result; root@9: } root@9: root@9: /** root@9: * Returns the end of a message boundary. root@9: * @access private root@9: */ root@9: private function EndBoundary($boundary) { root@9: return $this->LE . '--' . $boundary . '--' . $this->LE; root@9: } root@9: root@9: /** root@9: * Sets the message type. root@9: * @access private root@9: * @return void root@9: */ root@9: private function SetMessageType() { root@9: if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) { root@9: $this->message_type = 'plain'; root@9: } else { root@9: if(count($this->attachment) > 0) { root@9: $this->message_type = 'attachments'; root@9: } root@9: if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) { root@9: $this->message_type = 'alt'; root@9: } root@9: if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) { root@9: $this->message_type = 'alt_attachments'; root@9: } root@9: } root@9: } root@9: root@9: /** root@9: * Returns a formatted header line. root@9: * @access public root@9: * @return string root@9: */ root@9: public function HeaderLine($name, $value) { root@9: return $name . ': ' . $value . $this->LE; root@9: } root@9: root@9: /** root@9: * Returns a formatted mail line. root@9: * @access public root@9: * @return string root@9: */ root@9: public function TextLine($value) { root@9: return $value . $this->LE; root@9: } root@9: root@9: ///////////////////////////////////////////////// root@9: // CLASS METHODS, ATTACHMENTS root@9: ///////////////////////////////////////////////// root@9: root@9: /** root@9: * Adds an attachment from a path on the filesystem. root@9: * Returns false if the file could not be found root@9: * or accessed. root@9: * @param string $path Path to the attachment. root@9: * @param string $name Overrides the attachment name. root@9: * @param string $encoding File encoding (see $Encoding). root@9: * @param string $type File extension (MIME) type. root@9: * @return bool root@9: */ root@9: public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { root@9: try { root@9: if ( !@is_file($path) ) { root@9: throw new phpmailerException($this->Lang('file_access') . $path, self::STOP_CONTINUE); root@9: } root@9: $filename = basename($path); root@9: if ( $name == '' ) { root@9: $name = $filename; root@9: } root@9: root@9: $this->attachment[] = array( root@9: 0 => $path, root@9: 1 => $filename, root@9: 2 => $name, root@9: 3 => $encoding, root@9: 4 => $type, root@9: 5 => false, // isStringAttachment root@9: 6 => 'attachment', root@9: 7 => 0 root@9: ); root@9: root@9: } catch (phpmailerException $e) { root@9: $this->SetError($e->getMessage()); root@9: if ($this->exceptions) { root@9: throw $e; root@9: } root@9: echo $e->getMessage()."\n"; root@9: if ( $e->getCode() == self::STOP_CRITICAL ) { root@9: return false; root@9: } root@9: } root@9: return true; root@9: } root@9: root@9: /** root@9: * Return the current array of attachments root@9: * @return array root@9: */ root@9: public function GetAttachments() { root@9: return $this->attachment; root@9: } root@9: root@9: /** root@9: * Attaches all fs, string, and binary attachments to the message. root@9: * Returns an empty string on failure. root@9: * @access private root@9: * @return string root@9: */ root@9: private function AttachAll() { root@9: // Return text of body root@9: $mime = array(); root@9: $cidUniq = array(); root@9: $incl = array(); root@9: root@9: // Add all attachments root@9: foreach ($this->attachment as $attachment) { root@9: // Check for string attachment root@9: $bString = $attachment[5]; root@9: if ($bString) { root@9: $string = $attachment[0]; root@9: } else { root@9: $path = $attachment[0]; root@9: } root@9: root@9: if (in_array($attachment[0], $incl)) { continue; } root@9: $filename = $attachment[1]; root@9: $name = $attachment[2]; root@9: $encoding = $attachment[3]; root@9: $type = $attachment[4]; root@9: $disposition = $attachment[6]; root@9: $cid = $attachment[7]; root@9: $incl[] = $attachment[0]; root@9: if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; } root@9: $cidUniq[$cid] = true; root@9: root@9: $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE); root@9: $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE); root@9: $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); root@9: root@9: if($disposition == 'inline') { root@9: $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); root@9: } root@9: root@9: $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE); root@9: root@9: // Encode as string attachment root@9: if($bString) { root@9: $mime[] = $this->EncodeString($string, $encoding); root@9: if($this->IsError()) { root@9: return ''; root@9: } root@9: $mime[] = $this->LE.$this->LE; root@9: } else { root@9: $mime[] = $this->EncodeFile($path, $encoding); root@9: if($this->IsError()) { root@9: return ''; root@9: } root@9: $mime[] = $this->LE.$this->LE; root@9: } root@9: } root@9: root@9: $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE); root@9: root@9: return join('', $mime); root@9: } root@9: root@9: /** root@9: * Encodes attachment in requested format. root@9: * Returns an empty string on failure. root@9: * @param string $path The full path to the file root@9: * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' root@9: * @see EncodeFile() root@9: * @access private root@9: * @return string root@9: */ root@9: private function EncodeFile($path, $encoding = 'base64') { root@9: try { root@9: if (!is_readable($path)) { root@9: throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE); root@9: } root@9: if (function_exists('get_magic_quotes')) { root@9: function get_magic_quotes() { root@9: return false; root@9: } root@9: } root@9: if (PHP_VERSION < 6) { root@9: $magic_quotes = get_magic_quotes_runtime(); root@9: set_magic_quotes_runtime(0); root@9: } root@9: $file_buffer = file_get_contents($path); root@9: $file_buffer = $this->EncodeString($file_buffer, $encoding); root@9: if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); } root@9: return $file_buffer; root@9: } catch (Exception $e) { root@9: $this->SetError($e->getMessage()); root@9: return ''; root@9: } root@9: } root@9: root@9: /** root@9: * Encodes string to requested format. root@9: * Returns an empty string on failure. root@9: * @param string $str The text to encode root@9: * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' root@9: * @access public root@9: * @return string root@9: */ root@9: public function EncodeString ($str, $encoding = 'base64') { root@9: $encoded = ''; root@9: switch(strtolower($encoding)) { root@9: case 'base64': root@9: $encoded = chunk_split(base64_encode($str), 76, $this->LE); root@9: break; root@9: case '7bit': root@9: case '8bit': root@9: $encoded = $this->FixEOL($str); root@9: //Make sure it ends with a line break root@9: if (substr($encoded, -(strlen($this->LE))) != $this->LE) root@9: $encoded .= $this->LE; root@9: break; root@9: case 'binary': root@9: $encoded = $str; root@9: break; root@9: case 'quoted-printable': root@9: $encoded = $this->EncodeQP($str); root@9: break; root@9: default: root@9: $this->SetError($this->Lang('encoding') . $encoding); root@9: break; root@9: } root@9: return $encoded; root@9: } root@9: root@9: /** root@9: * Encode a header string to best (shortest) of Q, B, quoted or none. root@9: * @access public root@9: * @return string root@9: */ root@9: public function EncodeHeader($str, $position = 'text') { root@9: $x = 0; root@9: root@9: switch (strtolower($position)) { root@9: case 'phrase': root@9: if (!preg_match('/[\200-\377]/', $str)) { root@9: // Can't use addslashes as we don't know what value has magic_quotes_sybase root@9: $encoded = addcslashes($str, "\0..\37\177\\\""); root@9: if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) { root@9: return ($encoded); root@9: } else { root@9: return ("\"$encoded\""); root@9: } root@9: } root@9: $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches); root@9: break; root@9: case 'comment': root@9: $x = preg_match_all('/[()"]/', $str, $matches); root@9: // Fall-through root@9: case 'text': root@9: default: root@9: $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches); root@9: break; root@9: } root@9: root@9: if ($x == 0) { root@9: return ($str); root@9: } root@9: root@9: $maxlen = 75 - 7 - strlen($this->CharSet); root@9: // Try to select the encoding which should produce the shortest output root@9: if (strlen($str)/3 < $x) { root@9: $encoding = 'B'; root@9: if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) { root@9: // Use a custom function which correctly encodes and wraps long root@9: // multibyte strings without breaking lines within a character root@9: $encoded = $this->Base64EncodeWrapMB($str); root@9: } else { root@9: $encoded = base64_encode($str); root@9: $maxlen -= $maxlen % 4; root@9: $encoded = trim(chunk_split($encoded, $maxlen, "\n")); root@9: } root@9: } else { root@9: $encoding = 'Q'; root@9: $encoded = $this->EncodeQ($str, $position); root@9: $encoded = $this->WrapText($encoded, $maxlen, true); root@9: $encoded = str_replace('='.$this->LE, "\n", trim($encoded)); root@9: } root@9: root@9: $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded); root@9: $encoded = trim(str_replace("\n", $this->LE, $encoded)); root@9: root@9: return $encoded; root@9: } root@9: root@9: /** root@9: * Checks if a string contains multibyte characters. root@9: * @access public root@9: * @param string $str multi-byte text to wrap encode root@9: * @return bool root@9: */ root@9: public function HasMultiBytes($str) { root@9: if (function_exists('mb_strlen')) { root@9: return (strlen($str) > mb_strlen($str, $this->CharSet)); root@9: } else { // Assume no multibytes (we can't handle without mbstring functions anyway) root@9: return false; root@9: } root@9: } root@9: root@9: /** root@9: * Correctly encodes and wraps long multibyte strings for mail headers root@9: * without breaking lines within a character. root@9: * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php root@9: * @access public root@9: * @param string $str multi-byte text to wrap encode root@9: * @return string root@9: */ root@9: public function Base64EncodeWrapMB($str) { root@9: $start = "=?".$this->CharSet."?B?"; root@9: $end = "?="; root@9: $encoded = ""; root@9: root@9: $mb_length = mb_strlen($str, $this->CharSet); root@9: // Each line must have length <= 75, including $start and $end root@9: $length = 75 - strlen($start) - strlen($end); root@9: // Average multi-byte ratio root@9: $ratio = $mb_length / strlen($str); root@9: // Base64 has a 4:3 ratio root@9: $offset = $avgLength = floor($length * $ratio * .75); root@9: root@9: for ($i = 0; $i < $mb_length; $i += $offset) { root@9: $lookBack = 0; root@9: root@9: do { root@9: $offset = $avgLength - $lookBack; root@9: $chunk = mb_substr($str, $i, $offset, $this->CharSet); root@9: $chunk = base64_encode($chunk); root@9: $lookBack++; root@9: } root@9: while (strlen($chunk) > $length); root@9: root@9: $encoded .= $chunk . $this->LE; root@9: } root@9: root@9: // Chomp the last linefeed root@9: $encoded = substr($encoded, 0, -strlen($this->LE)); root@9: return $encoded; root@9: } root@9: root@9: /** root@9: * Encode string to quoted-printable. root@9: * Only uses standard PHP, slow, but will always work root@9: * @access public root@9: * @param string $string the text to encode root@9: * @param integer $line_max Number of chars allowed on a line before wrapping root@9: * @return string root@9: */ root@9: public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) { root@9: $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); root@9: $lines = preg_split('/(?:\r\n|\r|\n)/', $input); root@9: $eol = "\r\n"; root@9: $escape = '='; root@9: $output = ''; root@9: while( list(, $line) = each($lines) ) { root@9: $linlen = strlen($line); root@9: $newline = ''; root@9: for($i = 0; $i < $linlen; $i++) { root@9: $c = substr( $line, $i, 1 ); root@9: $dec = ord( $c ); root@9: if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E root@9: $c = '=2E'; root@9: } root@9: if ( $dec == 32 ) { root@9: if ( $i == ( $linlen - 1 ) ) { // convert space at eol only root@9: $c = '=20'; root@9: } else if ( $space_conv ) { root@9: $c = '=20'; root@9: } root@9: } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required root@9: $h2 = floor($dec/16); root@9: $h1 = floor($dec%16); root@9: $c = $escape.$hex[$h2].$hex[$h1]; root@9: } root@9: if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted root@9: $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay root@9: $newline = ''; root@9: // check if newline first character will be point or not root@9: if ( $dec == 46 ) { root@9: $c = '=2E'; root@9: } root@9: } root@9: $newline .= $c; root@9: } // end of for root@9: $output .= $newline.$eol; root@9: } // end of while root@9: return $output; root@9: } root@9: root@9: /** root@9: * Encode string to RFC2045 (6.7) quoted-printable format root@9: * Uses a PHP5 stream filter to do the encoding about 64x faster than the old version root@9: * Also results in same content as you started with after decoding root@9: * @see EncodeQPphp() root@9: * @access public root@9: * @param string $string the text to encode root@9: * @param integer $line_max Number of chars allowed on a line before wrapping root@9: * @param boolean $space_conv Dummy param for compatibility with existing EncodeQP function root@9: * @return string root@9: * @author Marcus Bointon root@9: */ root@9: public function EncodeQP($string, $line_max = 76, $space_conv = false) { root@9: if (function_exists('quoted_printable_encode')) { //Use native function if it's available (>= PHP5.3) root@9: return quoted_printable_encode($string); root@9: } root@9: $filters = stream_get_filters(); root@9: if (!in_array('convert.*', $filters)) { //Got convert stream filter? root@9: return $this->EncodeQPphp($string, $line_max, $space_conv); //Fall back to old implementation root@9: } root@9: $fp = fopen('php://temp/', 'r+'); root@9: $string = preg_replace('/\r\n?/', $this->LE, $string); //Normalise line breaks root@9: $params = array('line-length' => $line_max, 'line-break-chars' => $this->LE); root@9: $s = stream_filter_append($fp, 'convert.quoted-printable-encode', STREAM_FILTER_READ, $params); root@9: fputs($fp, $string); root@9: rewind($fp); root@9: $out = stream_get_contents($fp); root@9: stream_filter_remove($s); root@9: $out = preg_replace('/^\./m', '=2E', $out); //Encode . if it is first char on a line, workaround for bug in Exchange root@9: fclose($fp); root@9: return $out; root@9: } root@9: root@9: /** root@9: * Encode string to q encoding. root@9: * @link http://tools.ietf.org/html/rfc2047 root@9: * @param string $str the text to encode root@9: * @param string $position Where the text is going to be used, see the RFC for what that means root@9: * @access public root@9: * @return string root@9: */ root@9: public function EncodeQ ($str, $position = 'text') { root@9: // There should not be any EOL in the string root@9: $encoded = preg_replace('/[\r\n]*/', '', $str); root@9: root@9: switch (strtolower($position)) { root@9: case 'phrase': root@9: $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); root@9: break; root@9: case 'comment': root@9: $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); root@9: case 'text': root@9: default: root@9: // Replace every high ascii, control =, ? and _ characters root@9: //TODO using /e (equivalent to eval()) is probably not a good idea root@9: $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', root@9: "'='.sprintf('%02X', ord('\\1'))", $encoded); root@9: break; root@9: } root@9: root@9: // Replace every spaces to _ (more readable than =20) root@9: $encoded = str_replace(' ', '_', $encoded); root@9: root@9: return $encoded; root@9: } root@9: root@9: /** root@9: * Adds a string or binary attachment (non-filesystem) to the list. root@9: * This method can be used to attach ascii or binary data, root@9: * such as a BLOB record from a database. root@9: * @param string $string String attachment data. root@9: * @param string $filename Name of the attachment. root@9: * @param string $encoding File encoding (see $Encoding). root@9: * @param string $type File extension (MIME) type. root@9: * @return void root@9: */ root@9: public function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') { root@9: // Append to $attachment array root@9: $this->attachment[] = array( root@9: 0 => $string, root@9: 1 => $filename, root@9: 2 => basename($filename), root@9: 3 => $encoding, root@9: 4 => $type, root@9: 5 => true, // isStringAttachment root@9: 6 => 'attachment', root@9: 7 => 0 root@9: ); root@9: } root@9: root@9: /** root@9: * Adds an embedded attachment. This can include images, sounds, and root@9: * just about any other document. Make sure to set the $type to an root@9: * image type. For JPEG images use "image/jpeg" and for GIF images root@9: * use "image/gif". root@9: * @param string $path Path to the attachment. root@9: * @param string $cid Content ID of the attachment. Use this to identify root@9: * the Id for accessing the image in an HTML form. root@9: * @param string $name Overrides the attachment name. root@9: * @param string $encoding File encoding (see $Encoding). root@9: * @param string $type File extension (MIME) type. root@9: * @return bool root@9: */ root@9: public function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { root@9: root@9: if ( !@is_file($path) ) { root@9: $this->SetError($this->Lang('file_access') . $path); root@9: return false; root@9: } root@9: root@9: $filename = basename($path); root@9: if ( $name == '' ) { root@9: $name = $filename; root@9: } root@9: root@9: // Append to $attachment array root@9: $this->attachment[] = array( root@9: 0 => $path, root@9: 1 => $filename, root@9: 2 => $name, root@9: 3 => $encoding, root@9: 4 => $type, root@9: 5 => false, // isStringAttachment root@9: 6 => 'inline', root@9: 7 => $cid root@9: ); root@9: root@9: return true; root@9: } root@9: root@9: /** root@9: * Returns true if an inline attachment is present. root@9: * @access public root@9: * @return bool root@9: */ root@9: public function InlineImageExists() { root@9: foreach($this->attachment as $attachment) { root@9: if ($attachment[6] == 'inline') { root@9: return true; root@9: } root@9: } root@9: return false; root@9: } root@9: root@9: ///////////////////////////////////////////////// root@9: // CLASS METHODS, MESSAGE RESET root@9: ///////////////////////////////////////////////// root@9: root@9: /** root@9: * Clears all recipients assigned in the TO array. Returns void. root@9: * @return void root@9: */ root@9: public function ClearAddresses() { root@9: foreach($this->to as $to) { root@9: unset($this->all_recipients[strtolower($to[0])]); root@9: } root@9: $this->to = array(); root@9: } root@9: root@9: /** root@9: * Clears all recipients assigned in the CC array. Returns void. root@9: * @return void root@9: */ root@9: public function ClearCCs() { root@9: foreach($this->cc as $cc) { root@9: unset($this->all_recipients[strtolower($cc[0])]); root@9: } root@9: $this->cc = array(); root@9: } root@9: root@9: /** root@9: * Clears all recipients assigned in the BCC array. Returns void. root@9: * @return void root@9: */ root@9: public function ClearBCCs() { root@9: foreach($this->bcc as $bcc) { root@9: unset($this->all_recipients[strtolower($bcc[0])]); root@9: } root@9: $this->bcc = array(); root@9: } root@9: root@9: /** root@9: * Clears all recipients assigned in the ReplyTo array. Returns void. root@9: * @return void root@9: */ root@9: public function ClearReplyTos() { root@9: $this->ReplyTo = array(); root@9: } root@9: root@9: /** root@9: * Clears all recipients assigned in the TO, CC and BCC root@9: * array. Returns void. root@9: * @return void root@9: */ root@9: public function ClearAllRecipients() { root@9: $this->to = array(); root@9: $this->cc = array(); root@9: $this->bcc = array(); root@9: $this->all_recipients = array(); root@9: } root@9: root@9: /** root@9: * Clears all previously set filesystem, string, and binary root@9: * attachments. Returns void. root@9: * @return void root@9: */ root@9: public function ClearAttachments() { root@9: $this->attachment = array(); root@9: } root@9: root@9: /** root@9: * Clears all custom headers. Returns void. root@9: * @return void root@9: */ root@9: public function ClearCustomHeaders() { root@9: $this->CustomHeader = array(); root@9: } root@9: root@9: ///////////////////////////////////////////////// root@9: // CLASS METHODS, MISCELLANEOUS root@9: ///////////////////////////////////////////////// root@9: root@9: /** root@9: * Adds the error message to the error container. root@9: * @access protected root@9: * @return void root@9: */ root@9: protected function SetError($msg) { root@9: $this->error_count++; root@9: if ($this->Mailer == 'smtp' and !is_null($this->smtp)) { root@9: $lasterror = $this->smtp->getError(); root@9: if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) { root@9: $msg .= '

' . $this->Lang('smtp_error') . $lasterror['smtp_msg'] . "

\n"; root@9: } root@9: } root@9: $this->ErrorInfo = $msg; root@9: } root@9: root@9: /** root@9: * Returns the proper RFC 822 formatted date. root@9: * @access public root@9: * @return string root@9: * @static root@9: */ root@9: public static function RFCDate() { root@9: $tz = date('Z'); root@9: $tzs = ($tz < 0) ? '-' : '+'; root@9: $tz = abs($tz); root@9: $tz = (int)($tz/3600)*100 + ($tz%3600)/60; root@9: $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz); root@9: root@9: return $result; root@9: } root@9: root@9: /** root@9: * Returns the server hostname or 'localhost.localdomain' if unknown. root@9: * @access private root@9: * @return string root@9: */ root@9: private function ServerHostname() { root@9: if (!empty($this->Hostname)) { root@9: $result = $this->Hostname; root@9: } elseif (isset($_SERVER['SERVER_NAME'])) { root@9: $result = $_SERVER['SERVER_NAME']; root@9: } else { root@9: $result = 'localhost.localdomain'; root@9: } root@9: root@9: return $result; root@9: } root@9: root@9: /** root@9: * Returns a message in the appropriate language. root@9: * @access private root@9: * @return string root@9: */ root@9: private function Lang($key) { root@9: if(count($this->language) < 1) { root@9: $this->SetLanguage('en'); // set the default language root@9: } root@9: root@9: if(isset($this->language[$key])) { root@9: return $this->language[$key]; root@9: } else { root@9: return 'Language string failed to load: ' . $key; root@9: } root@9: } root@9: root@9: /** root@9: * Returns true if an error occurred. root@9: * @access public root@9: * @return bool root@9: */ root@9: public function IsError() { root@9: return ($this->error_count > 0); root@9: } root@9: root@9: /** root@9: * Changes every end of line from CR or LF to CRLF. root@9: * @access private root@9: * @return string root@9: */ root@9: private function FixEOL($str) { root@9: $str = str_replace("\r\n", "\n", $str); root@9: $str = str_replace("\r", "\n", $str); root@9: $str = str_replace("\n", $this->LE, $str); root@9: return $str; root@9: } root@9: root@9: /** root@9: * Adds a custom header. root@9: * @access public root@9: * @return void root@9: */ root@9: public function AddCustomHeader($custom_header) { root@9: $this->CustomHeader[] = explode(':', $custom_header, 2); root@9: } root@9: root@9: /** root@9: * Evaluates the message and returns modifications for inline images and backgrounds root@9: * @access public root@9: * @return $message root@9: */ root@9: public function MsgHTML($message, $basedir = '') { root@9: preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images); root@9: if(isset($images[2])) { root@9: foreach($images[2] as $i => $url) { root@9: // do not change urls for absolute images (thanks to corvuscorax) root@9: if (!preg_match('#^[A-z]+://#',$url)) { root@9: $filename = basename($url); root@9: $directory = dirname($url); root@9: ($directory == '.')?$directory='':''; root@9: $cid = 'cid:' . md5($filename); root@9: $ext = pathinfo($filename, PATHINFO_EXTENSION); root@9: $mimeType = self::_mime_types($ext); root@9: if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; } root@9: if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; } root@9: if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) { root@9: $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message); root@9: } root@9: } root@9: } root@9: } root@9: $this->IsHTML(true); root@9: $this->Body = $message; root@9: $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message))); root@9: if (!empty($textMsg) && empty($this->AltBody)) { root@9: $this->AltBody = html_entity_decode($textMsg); root@9: } root@9: if (empty($this->AltBody)) { root@9: $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n"; root@9: } root@9: } root@9: root@9: /** root@9: * Gets the MIME type of the embedded or inline image root@9: * @param string File extension root@9: * @access public root@9: * @return string MIME type of ext root@9: * @static root@9: */ root@9: public static function _mime_types($ext = '') { root@9: $mimes = array( root@9: 'hqx' => 'application/mac-binhex40', root@9: 'cpt' => 'application/mac-compactpro', root@9: 'doc' => 'application/msword', root@9: 'bin' => 'application/macbinary', root@9: 'dms' => 'application/octet-stream', root@9: 'lha' => 'application/octet-stream', root@9: 'lzh' => 'application/octet-stream', root@9: 'exe' => 'application/octet-stream', root@9: 'class' => 'application/octet-stream', root@9: 'psd' => 'application/octet-stream', root@9: 'so' => 'application/octet-stream', root@9: 'sea' => 'application/octet-stream', root@9: 'dll' => 'application/octet-stream', root@9: 'oda' => 'application/oda', root@9: 'pdf' => 'application/pdf', root@9: 'ai' => 'application/postscript', root@9: 'eps' => 'application/postscript', root@9: 'ps' => 'application/postscript', root@9: 'smi' => 'application/smil', root@9: 'smil' => 'application/smil', root@9: 'mif' => 'application/vnd.mif', root@9: 'xls' => 'application/vnd.ms-excel', root@9: 'ppt' => 'application/vnd.ms-powerpoint', root@9: 'wbxml' => 'application/vnd.wap.wbxml', root@9: 'wmlc' => 'application/vnd.wap.wmlc', root@9: 'dcr' => 'application/x-director', root@9: 'dir' => 'application/x-director', root@9: 'dxr' => 'application/x-director', root@9: 'dvi' => 'application/x-dvi', root@9: 'gtar' => 'application/x-gtar', root@9: 'php' => 'application/x-httpd-php', root@9: 'php4' => 'application/x-httpd-php', root@9: 'php3' => 'application/x-httpd-php', root@9: 'phtml' => 'application/x-httpd-php', root@9: 'phps' => 'application/x-httpd-php-source', root@9: 'js' => 'application/x-javascript', root@9: 'swf' => 'application/x-shockwave-flash', root@9: 'sit' => 'application/x-stuffit', root@9: 'tar' => 'application/x-tar', root@9: 'tgz' => 'application/x-tar', root@9: 'xhtml' => 'application/xhtml+xml', root@9: 'xht' => 'application/xhtml+xml', root@9: 'zip' => 'application/zip', root@9: 'mid' => 'audio/midi', root@9: 'midi' => 'audio/midi', root@9: 'mpga' => 'audio/mpeg', root@9: 'mp2' => 'audio/mpeg', root@9: 'mp3' => 'audio/mpeg', root@9: 'aif' => 'audio/x-aiff', root@9: 'aiff' => 'audio/x-aiff', root@9: 'aifc' => 'audio/x-aiff', root@9: 'ram' => 'audio/x-pn-realaudio', root@9: 'rm' => 'audio/x-pn-realaudio', root@9: 'rpm' => 'audio/x-pn-realaudio-plugin', root@9: 'ra' => 'audio/x-realaudio', root@9: 'rv' => 'video/vnd.rn-realvideo', root@9: 'wav' => 'audio/x-wav', root@9: 'bmp' => 'image/bmp', root@9: 'gif' => 'image/gif', root@9: 'jpeg' => 'image/jpeg', root@9: 'jpg' => 'image/jpeg', root@9: 'jpe' => 'image/jpeg', root@9: 'png' => 'image/png', root@9: 'tiff' => 'image/tiff', root@9: 'tif' => 'image/tiff', root@9: 'css' => 'text/css', root@9: 'html' => 'text/html', root@9: 'htm' => 'text/html', root@9: 'shtml' => 'text/html', root@9: 'txt' => 'text/plain', root@9: 'text' => 'text/plain', root@9: 'log' => 'text/plain', root@9: 'rtx' => 'text/richtext', root@9: 'rtf' => 'text/rtf', root@9: 'xml' => 'text/xml', root@9: 'xsl' => 'text/xml', root@9: 'mpeg' => 'video/mpeg', root@9: 'mpg' => 'video/mpeg', root@9: 'mpe' => 'video/mpeg', root@9: 'qt' => 'video/quicktime', root@9: 'mov' => 'video/quicktime', root@9: 'avi' => 'video/x-msvideo', root@9: 'movie' => 'video/x-sgi-movie', root@9: 'doc' => 'application/msword', root@9: 'word' => 'application/msword', root@9: 'xl' => 'application/excel', root@9: 'eml' => 'message/rfc822' root@9: ); root@9: return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; root@9: } root@9: root@9: /** root@9: * Set (or reset) Class Objects (variables) root@9: * root@9: * Usage Example: root@9: * $page->set('X-Priority', '3'); root@9: * root@9: * @access public root@9: * @param string $name Parameter Name root@9: * @param mixed $value Parameter Value root@9: * NOTE: will not work with arrays, there are no arrays to set/reset root@9: * @todo Should this not be using __set() magic function? root@9: */ root@9: public function set($name, $value = '') { root@9: try { root@9: if (isset($this->$name) ) { root@9: $this->$name = $value; root@9: } else { root@9: throw new phpmailerException($this->Lang('variable_set') . $name, self::STOP_CRITICAL); root@9: } root@9: } catch (Exception $e) { root@9: $this->SetError($e->getMessage()); root@9: if ($e->getCode() == self::STOP_CRITICAL) { root@9: return false; root@9: } root@9: } root@9: return true; root@9: } root@9: root@9: /** root@9: * Strips newlines to prevent header injection. root@9: * @access public root@9: * @param string $str String root@9: * @return string root@9: */ root@9: public function SecureHeader($str) { root@9: $str = str_replace("\r", '', $str); root@9: $str = str_replace("\n", '', $str); root@9: return trim($str); root@9: } root@9: root@9: /** root@9: * Set the private key file and password to sign the message. root@9: * root@9: * @access public root@9: * @param string $key_filename Parameter File Name root@9: * @param string $key_pass Password for private key root@9: */ root@9: public function Sign($cert_filename, $key_filename, $key_pass) { root@9: $this->sign_cert_file = $cert_filename; root@9: $this->sign_key_file = $key_filename; root@9: $this->sign_key_pass = $key_pass; root@9: } root@9: root@9: /** root@9: * Set the private key file and password to sign the message. root@9: * root@9: * @access public root@9: * @param string $key_filename Parameter File Name root@9: * @param string $key_pass Password for private key root@9: */ root@9: public function DKIM_QP($txt) { root@9: $tmp=""; root@9: $line=""; root@9: for ($i=0;$iDKIM_private); root@9: if ($this->DKIM_passphrase!='') { root@9: $privKey = openssl_pkey_get_private($privKeyStr,$this->DKIM_passphrase); root@9: } else { root@9: $privKey = $privKeyStr; root@9: } root@9: if (openssl_sign($s, $signature, $privKey)) { root@9: return base64_encode($signature); root@9: } root@9: } root@9: root@9: /** root@9: * Generate DKIM Canonicalization Header root@9: * root@9: * @access public root@9: * @param string $s Header root@9: */ root@9: public function DKIM_HeaderC($s) { root@9: $s=preg_replace("/\r\n\s+/"," ",$s); root@9: $lines=explode("\r\n",$s); root@9: foreach ($lines as $key=>$line) { root@9: list($heading,$value)=explode(":",$line,2); root@9: $heading=strtolower($heading); root@9: $value=preg_replace("/\s+/"," ",$value) ; // Compress useless spaces root@9: $lines[$key]=$heading.":".trim($value) ; // Don't forget to remove WSP around the value root@9: } root@9: $s=implode("\r\n",$lines); root@9: return $s; root@9: } root@9: root@9: /** root@9: * Generate DKIM Canonicalization Body root@9: * root@9: * @access public root@9: * @param string $body Message Body root@9: */ root@9: public function DKIM_BodyC($body) { root@9: if ($body == '') return "\r\n"; root@9: // stabilize line endings root@9: $body=str_replace("\r\n","\n",$body); root@9: $body=str_replace("\n","\r\n",$body); root@9: // END stabilize line endings root@9: while (substr($body,strlen($body)-4,4) == "\r\n\r\n") { root@9: $body=substr($body,0,strlen($body)-2); root@9: } root@9: return $body; root@9: } root@9: root@9: /** root@9: * Create the DKIM header, body, as new header root@9: * root@9: * @access public root@9: * @param string $headers_line Header lines root@9: * @param string $subject Subject root@9: * @param string $body Body root@9: */ root@9: public function DKIM_Add($headers_line,$subject,$body) { root@9: $DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms root@9: $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body root@9: $DKIMquery = 'dns/txt'; // Query method root@9: $DKIMtime = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone) root@9: $subject_header = "Subject: $subject"; root@9: $headers = explode("\r\n",$headers_line); root@9: foreach($headers as $header) { root@9: if (strpos($header,'From:') === 0) { root@9: $from_header=$header; root@9: } elseif (strpos($header,'To:') === 0) { root@9: $to_header=$header; root@9: } root@9: } root@9: $from = str_replace('|','=7C',$this->DKIM_QP($from_header)); root@9: $to = str_replace('|','=7C',$this->DKIM_QP($to_header)); root@9: $subject = str_replace('|','=7C',$this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable root@9: $body = $this->DKIM_BodyC($body); root@9: $DKIMlen = strlen($body) ; // Length of body root@9: $DKIMb64 = base64_encode(pack("H*", sha1($body))) ; // Base64 of packed binary SHA-1 hash of body root@9: $ident = ($this->DKIM_identity == '')? '' : " i=" . $this->DKIM_identity . ";"; root@9: $dkimhdrs = "DKIM-Signature: v=1; a=" . $DKIMsignatureType . "; q=" . $DKIMquery . "; l=" . $DKIMlen . "; s=" . $this->DKIM_selector . ";\r\n". root@9: "\tt=" . $DKIMtime . "; c=" . $DKIMcanonicalization . ";\r\n". root@9: "\th=From:To:Subject;\r\n". root@9: "\td=" . $this->DKIM_domain . ";" . $ident . "\r\n". root@9: "\tz=$from\r\n". root@9: "\t|$to\r\n". root@9: "\t|$subject;\r\n". root@9: "\tbh=" . $DKIMb64 . ";\r\n". root@9: "\tb="; root@9: $toSign = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs); root@9: $signed = $this->DKIM_Sign($toSign); root@9: return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n"; root@9: } root@9: root@9: protected function doCallback($isSent,$to,$cc,$bcc,$subject,$body) { root@9: if (!empty($this->action_function) && function_exists($this->action_function)) { root@9: $params = array($isSent,$to,$cc,$bcc,$subject,$body); root@9: call_user_func_array($this->action_function,$params); root@9: } root@9: } root@9: } root@9: root@9: class phpmailerException extends Exception { root@9: public function errorMessage() { root@9: $errorMsg = '' . $this->getMessage() . "
\n"; root@9: return $errorMsg; root@9: } root@9: } root@9: ?>