Id =$id; $this->boundary[1] = "----=_NextPart_" . $this->Id; } public function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream',$cid=0,$mode='attachment') { // Append to $attachment array $this->attachment[] = array( 0 => $string, 1 => $filename, 2 => basename($filename), 3 => $encoding, 4 => $type, 5 => true, // isStringAttachment 6 => $mode, 7 => $cid ); } public function CreateBody($message_type='') { $body = ''; if ($this->sign_key_file) { $body .= $this->GetMailMIME(); } $this->SetWordWrap(); if(!$message_type) $message_type=$this->message_type; switch($message_type) { case 'inline': $body .= $this->AttachAll("inline", $this->boundary[1]); break; case 'attach': $body .= $this->AttachAll("attachment", $this->boundary[1]); break; case 'inline_attach': $body .= $this->TextLine("--" . $this->boundary[1]); $body .= $this->HeaderLine('Content-Type', 'multipart/related;'); $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"'); $body .= $this->LE.$this->LE; $body .= $this->AttachAll("inline", $this->boundary[2]); $body .= $this->LE; $body .= $this->AttachAll("attachment", $this->boundary[1]); break; } if ($this->IsError()) { $body = ''; } elseif ($this->sign_key_file) { try { $file = tempnam('', 'mail'); file_put_contents($file, $body); //TODO check this worked $signed = tempnam("", "signed"); if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), NULL)) { @unlink($file); @unlink($signed); $body = file_get_contents($signed); } else { @unlink($file); @unlink($signed); throw new phpmailerException($this->Lang("signing").openssl_error_string()); } } catch (phpmailerException $e) { $body = ''; if ($this->exceptions) { throw $e; } } } return $body; } /** * Assembles message header. * @ignore * @return string */ function CreateHeader() { $result = ""; $this->Mailer = 'mail'; // Set the boundaries $uniq_id = $this->Id ; $this->boundary[1] = "----=_NextPart_" . $uniq_id; $result = $this->HeaderLine("MIME-Version", "1.0"); $result .= trim($this->GetMailMIME()); IF(isset($this->start)) { if($this->attachment[$this->start][4]) $result.="; type=\"{$this->attachment[0][4]}\""; if($this->attachment[$this->start][7]) $result.="; start=\"<{$this->attachment[0][7]}>\""; } return $result.$this->LE.$this->LE; } /** * Attaches all fs, string, and binary attachments to the message. * Returns an empty string on failure. * @ignore * @return string */ function AttachAll() { // Return text of body $mime = array(); // Add all attachments for($i = 0; $i < count($this->attachment); $i++) { // Check for string attachment $string = $this->attachment[$i][0]; if(is_file($string)) $string=file_get_contents($string); $filename = $this->attachment[$i][1]; $name = $this->attachment[$i][2]; $encoding = $this->attachment[$i][3]; $type = $this->attachment[$i][4]; $disposition = $this->attachment[$i][6]; $cid = $this->attachment[$i][7]; $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE); if($cid) $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); else $mime[] = sprintf("Content-Location: file:///%s%s",$filename, $this->LE); $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); $mime[] = sprintf("Content-Type: %s%s", $type, $this->LE); // Encode as string attachment $mime[] = $this->LE; $mime[] = $this->EncodeString($string, $encoding); $mime[] = $this->LE.$this->LE; } $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE); return join("", $mime); } function prepare(){ $this->SetMessageType(); } function get_boundary(){ return str_replace('----=','',$this->boundary[1]); } /** * @ignore */ public function SetAttachments($attachments) { $this->attachment=$attachments; return $this; } function __toString(){ $this->SetMessageType(); return $this->CreateHeader().$this->CreateBody(); } } ?>