예제 #1
0
 function _writemsg()
 {
     if (!$this->_fromaddr) {
         $fromaddr = ini_get('sendmail_from');
         if ($fromaddr == "") {
             if (isset($_SERVER['SERVER_ADMIN']) && FUNC::is_mail($_SERVER['SERVER_ADMIN'])) {
                 $fromaddr = $_SERVER['SERVER_ADMIN'];
             } elseif (isset($_SERVER['SERVER_NAME'])) {
                 $fromaddr = 'postmaster@' . $_SERVER['SERVER_NAME'];
             } elseif (isset($_SERVER['HTTP_HOST'])) {
                 $fromaddr = 'postmaster@' . $_SERVER['HTTP_HOST'];
             } elseif (isset($_SERVER['REMOTE_ADDR'])) {
                 $fromaddr = 'postmaster@' . $_SERVER['REMOTE_ADDR'];
             } elseif (isset($_SERVER['SERVER_ADDR'])) {
                 $fromaddr = 'postmaster@' . $_SERVER['SERVER_ADDR'];
             } else {
                 $fromaddr = 'postmaster@localhost';
             }
         }
         $this->_fromaddr = array('address' => $fromaddr, 'name' => '');
     }
     if (!$this->_fromhost) {
         if (isset($_SERVER['SERVER_NAME'])) {
             $this->_fromhost = $_SERVER['SERVER_NAME'];
         } elseif (isset($_SERVER['HTTP_HOST'])) {
             $this->_fromhost = $_SERVER['HTTP_HOST'];
         } elseif (isset($_SERVER['REMOTE_ADDR'])) {
             $this->_fromhost = $_SERVER['REMOTE_ADDR'];
         } elseif (isset($_SERVER['SERVER_ADDR'])) {
             $this->_fromhost = $_SERVER['SERVER_ADDR'];
         } else {
             $fexp = explode('@', $this->_fromaddr['address']);
             $this->_fromhost = $fexp[1];
         }
     }
     $tostr = $ccstr = $bccstr = '';
     foreach ($this->_toaddrs as $taddr => $tname) {
         if ($tname == "") {
             $tostr .= $taddr . ', ';
         } else {
             $tostr .= '"' . str_replace('"', '\\"', $tname) . '" <' . $taddr . '>, ';
         }
     }
     $tostr = $hto = substr($tostr, 0, -2);
     if ($this->_ccaddrs && count($this->_ccaddrs) > 0) {
         foreach ($this->_ccaddrs as $caddr => $cname) {
             if ($cname == "") {
                 $ccstr .= $caddr . ', ';
             } else {
                 $ccstr .= '"' . str_replace('"', '\\"', $cname) . '" <' . $caddr . '>, ';
             }
         }
         $ccstr = substr($ccstr, 0, -2);
     }
     if ($this->_bccaddrs && count($this->_bccaddrs) > 0) {
         foreach ($this->_bccaddrs as $baddr => $bname) {
             $bccstr .= $baddr . ', ';
         }
         $bccstr = substr($bccstr, 0, -2);
     }
     if ($this->_fromaddr['name'] == "") {
         $fromstr = $this->_fromaddr['address'];
     } else {
         $fromstr = '"' . str_replace('"', '\\"', $this->_fromaddr['name']) . '" <' . $this->_fromaddr['address'] . '>';
     }
     $arrval1 = $arrval2 = array();
     $arrval1[] = array('name' => 'From', 'value' => $fromstr);
     $arrval2[] = array('name' => 'From', 'value' => $fromstr);
     $arrval2[] = array('name' => 'To', 'value' => $tostr);
     $arrval2[] = array('name' => 'Subject', 'value' => $this->_subject);
     if ($ccstr != "") {
         $arrval1[] = array('name' => 'Cc', 'value' => $ccstr);
         $arrval2[] = array('name' => 'Cc', 'value' => $ccstr);
     }
     if ($bccstr != "") {
         $arrval1[] = array('name' => 'Bcc', 'value' => $bccstr);
     }
     $arrval2[] = array('name' => 'Date', 'value' => date('r'));
     if ($this->_header && count($this->_header) > 0) {
         foreach ($this->_header as $hvarr) {
             $arrval1[] = $hvarr;
             $arrval2[] = $hvarr;
         }
     }
     $xmail = array('name' => base64_decode('WC1NYWlsZXI='), 'value' => base64_decode('WFBNMiB2LjAuMSA8d3d3LnhwZXJ0bWFpbGVyLmNvbT4='));
     $arrval1[] = $xmail;
     $arrval2[] = $xmail;
     $hval1 = $hval2 = $bval = '';
     foreach ($arrval1 as $heach1) {
         $hval1 .= $heach1['name'] . ': ' . $heach1['value'] . $this->_crlf;
     }
     foreach ($arrval2 as $heach2) {
         $hval2 .= $heach2['name'] . ': ' . $heach2['value'] . $this->_crlf;
     }
     $multipart = false;
     if ($this->_atext && $this->_ahtml) {
         $multipart = true;
     }
     if ($this->_attach && count($this->_attach) > 0) {
         $multipart = true;
     }
     if ($multipart) {
         $bval .= 'This is a message in MIME Format. If you see this, your mail reader does not support this format.' . $this->_crlf . $this->_crlf;
         $boundary1 = '=_' . $this->_getunique();
         $boundary2 = '=_' . $this->_getunique();
         $boundary3 = '=_' . $this->_getunique();
         $haveatt = $this->_attach && count($this->_attach) > 0 ? true : false;
         $inline = $attachment = false;
         $idarr = array();
         if ($haveatt) {
             foreach ($this->_attach as $attdesc) {
                 if ($attdesc['disp'] == "inline") {
                     $inline = true;
                     $fname = $attdesc['name'];
                     if (!isset($idarr[$fname])) {
                         $idarr[$fname] = $this->_getunique();
                     }
                 } else {
                     $attachment = true;
                 }
             }
         }
         $hadd = '';
         if ($this->_atext && $this->_ahtml) {
             $vhtml = count($idarr) > 0 ? $this->_putcid($this->_ahtml[2], $idarr) : $this->_ahtml[2];
             if ($inline && $attachment) {
                 $hadd .= 'Content-Type: multipart/mixed;' . $this->_crlf . "\t" . 'boundary="' . $boundary1 . '"' . $this->_crlf;
                 $bval .= '--' . $boundary1 . $this->_crlf . 'Content-Type: multipart/related;' . $this->_crlf . "\t" . 'boundary="' . $boundary2 . '"' . $this->_crlf . $this->_crlf . '--' . $boundary2 . $this->_crlf . 'Content-Type: multipart/alternative;' . $this->_crlf . "\t" . 'boundary="' . $boundary3 . '"' . $this->_crlf . $this->_crlf . '--' . $boundary3 . $this->_crlf . $this->_atext[0] . $this->_crlf . $this->_crlf . $this->_encodemsg($this->_atext[2], $this->_atext[1]) . $this->_crlf . '--' . $boundary3 . $this->_crlf . $this->_ahtml[0] . $this->_crlf . $this->_crlf . $this->_encodemsg($vhtml, $this->_ahtml[1]) . $this->_crlf . '--' . $boundary3 . '--' . $this->_crlf;
                 foreach ($this->_attach as $attdesc) {
                     if ($attdesc['disp'] == "inline") {
                         $bval .= '--' . $boundary2 . $this->_crlf . 'Content-Type: ' . $attdesc['mime'] . $this->_crlf . 'Content-Transfer-Encoding: ' . $attdesc['encode'] . $this->_crlf . 'Content-Disposition: ' . $attdesc['disp'] . ';' . $this->_crlf . "\t" . 'filename="' . $attdesc['name'] . '"' . $this->_crlf . 'Content-ID: <' . $idarr[$attdesc['name']] . '>' . $this->_crlf . $this->_crlf . $this->_encodemsg($attdesc['source'], $attdesc['encode']);
                     }
                 }
                 $bval .= '--' . $boundary2 . '--' . $this->_crlf;
                 foreach ($this->_attach as $attdesc) {
                     if ($attdesc['disp'] == "attachment") {
                         $bval .= '--' . $boundary1 . $this->_crlf . 'Content-Type: ' . $attdesc['mime'] . $this->_crlf . 'Content-Transfer-Encoding: ' . $attdesc['encode'] . $this->_crlf . 'Content-Disposition: ' . $attdesc['disp'] . ';' . $this->_crlf . "\t" . 'filename="' . $attdesc['name'] . '"' . $this->_crlf . $this->_crlf . $this->_encodemsg($attdesc['source'], $attdesc['encode']);
                     }
                 }
                 $bval .= '--' . $boundary1 . '--';
             } elseif ($inline) {
                 $hadd .= 'Content-Type: multipart/related;' . $this->_crlf . "\t" . 'boundary="' . $boundary1 . '"' . $this->_crlf;
                 $bval .= '--' . $boundary1 . $this->_crlf . 'Content-Type: multipart/alternative;' . $this->_crlf . "\t" . 'boundary="' . $boundary2 . '"' . $this->_crlf . $this->_crlf . '--' . $boundary2 . $this->_crlf . $this->_atext[0] . $this->_crlf . $this->_crlf . $this->_encodemsg($this->_atext[2], $this->_atext[1]) . $this->_crlf . '--' . $boundary2 . $this->_crlf . $this->_ahtml[0] . $this->_crlf . $this->_crlf . $this->_encodemsg($vhtml, $this->_ahtml[1]) . $this->_crlf . '--' . $boundary2 . '--' . $this->_crlf;
                 foreach ($this->_attach as $attdesc) {
                     $bval .= '--' . $boundary1 . $this->_crlf . 'Content-Type: ' . $attdesc['mime'] . $this->_crlf . 'Content-Transfer-Encoding: ' . $attdesc['encode'] . $this->_crlf . 'Content-Disposition: ' . $attdesc['disp'] . ';' . $this->_crlf . "\t" . 'filename="' . $attdesc['name'] . '"' . $this->_crlf . 'Content-ID: <' . $idarr[$attdesc['name']] . '>' . $this->_crlf . $this->_crlf . $this->_encodemsg($attdesc['source'], $attdesc['encode']);
                 }
                 $bval .= '--' . $boundary1 . '--';
             } elseif ($attachment) {
                 $hadd .= 'Content-Type: multipart/mixed;' . $this->_crlf . "\t" . 'boundary="' . $boundary1 . '"' . $this->_crlf;
                 $bval .= '--' . $boundary1 . $this->_crlf . 'Content-Type: multipart/alternative;' . $this->_crlf . "\t" . 'boundary="' . $boundary2 . '"' . $this->_crlf . $this->_crlf . '--' . $boundary2 . $this->_crlf . $this->_atext[0] . $this->_crlf . $this->_crlf . $this->_encodemsg($this->_atext[2], $this->_atext[1]) . $this->_crlf . '--' . $boundary2 . $this->_crlf . $this->_ahtml[0] . $this->_crlf . $this->_crlf . $this->_encodemsg($vhtml, $this->_ahtml[1]) . $this->_crlf . '--' . $boundary2 . '--' . $this->_crlf;
                 foreach ($this->_attach as $attdesc) {
                     $bval .= '--' . $boundary1 . $this->_crlf . 'Content-Type: ' . $attdesc['mime'] . $this->_crlf . 'Content-Transfer-Encoding: ' . $attdesc['encode'] . $this->_crlf . 'Content-Disposition: ' . $attdesc['disp'] . ';' . $this->_crlf . "\t" . 'filename="' . $attdesc['name'] . '"' . $this->_crlf . $this->_crlf . $this->_encodemsg($attdesc['source'], $attdesc['encode']);
                 }
                 $bval .= '--' . $boundary1 . '--';
             } else {
                 $hadd .= 'Content-Type: multipart/alternative;' . $this->_crlf . "\t" . 'boundary="' . $boundary1 . '"' . $this->_crlf;
                 $bval .= '--' . $boundary1 . $this->_crlf . $this->_atext[0] . $this->_crlf . $this->_crlf . $this->_encodemsg($this->_atext[2], $this->_atext[1]) . $this->_crlf . '--' . $boundary1 . $this->_crlf . $this->_ahtml[0] . $this->_crlf . $this->_crlf . $this->_encodemsg($vhtml, $this->_ahtml[1]) . $this->_crlf . '--' . $boundary1 . '--';
             }
         } elseif ($this->_atext) {
             $hadd .= 'Content-Type: multipart/mixed;' . $this->_crlf . "\t" . 'boundary="' . $boundary1 . '"' . $this->_crlf;
             $bval .= '--' . $boundary1 . $this->_crlf . $this->_atext[0] . $this->_crlf . $this->_crlf . $this->_encodemsg($this->_atext[2], $this->_atext[1]) . $this->_crlf;
             foreach ($this->_attach as $attdesc) {
                 $bval .= '--' . $boundary1 . $this->_crlf . 'Content-Type: ' . $attdesc['mime'] . $this->_crlf . 'Content-Transfer-Encoding: ' . $attdesc['encode'] . $this->_crlf . 'Content-Disposition: ' . $attdesc['disp'] . ';' . $this->_crlf . "\t" . 'filename="' . $attdesc['name'] . '"' . $this->_crlf . $this->_crlf . $this->_encodemsg($attdesc['source'], $attdesc['encode']);
             }
             $bval .= '--' . $boundary1 . '--';
         } elseif ($this->_ahtml) {
             $vhtml = count($idarr) > 0 ? $this->_putcid($this->_ahtml[2], $idarr) : $this->_ahtml[2];
             if ($inline && $attachment) {
                 $hadd .= 'Content-Type: multipart/mixed;' . $this->_crlf . "\t" . 'boundary="' . $boundary1 . '"' . $this->_crlf;
                 $bval .= '--' . $boundary1 . $this->_crlf . 'Content-Type: multipart/related;' . $this->_crlf . "\t" . 'boundary="' . $boundary2 . '"' . $this->_crlf . $this->_crlf . '--' . $boundary2 . $this->_crlf . $this->_ahtml[0] . $this->_crlf . $this->_crlf . $this->_encodemsg($vhtml, $this->_ahtml[1]) . $this->_crlf;
                 foreach ($this->_attach as $attdesc) {
                     if ($attdesc['disp'] == "inline") {
                         $bval .= '--' . $boundary2 . $this->_crlf . 'Content-Type: ' . $attdesc['mime'] . $this->_crlf . 'Content-Transfer-Encoding: ' . $attdesc['encode'] . $this->_crlf . 'Content-Disposition: ' . $attdesc['disp'] . ';' . $this->_crlf . "\t" . 'filename="' . $attdesc['name'] . '"' . $this->_crlf . 'Content-ID: <' . $idarr[$attdesc['name']] . '>' . $this->_crlf . $this->_crlf . $this->_encodemsg($attdesc['source'], $attdesc['encode']);
                     }
                 }
                 $bval .= '--' . $boundary2 . '--' . $this->_crlf;
                 foreach ($this->_attach as $attdesc) {
                     if ($attdesc['disp'] == "attachment") {
                         $bval .= '--' . $boundary1 . $this->_crlf . 'Content-Type: ' . $attdesc['mime'] . $this->_crlf . 'Content-Transfer-Encoding: ' . $attdesc['encode'] . $this->_crlf . 'Content-Disposition: ' . $attdesc['disp'] . ';' . $this->_crlf . "\t" . 'filename="' . $attdesc['name'] . '"' . $this->_crlf . $this->_crlf . $this->_encodemsg($attdesc['source'], $attdesc['encode']);
                     }
                 }
                 $bval .= '--' . $boundary1 . '--';
             } elseif ($inline) {
                 $hadd .= 'Content-Type: multipart/related;' . $this->_crlf . "\t" . 'boundary="' . $boundary1 . '"' . $this->_crlf;
                 $bval .= '--' . $boundary1 . $this->_crlf . $this->_ahtml[0] . $this->_crlf . $this->_crlf . $this->_encodemsg($vhtml, $this->_ahtml[1]) . $this->_crlf;
                 foreach ($this->_attach as $attdesc) {
                     $bval .= '--' . $boundary1 . $this->_crlf . 'Content-Type: ' . $attdesc['mime'] . $this->_crlf . 'Content-Transfer-Encoding: ' . $attdesc['encode'] . $this->_crlf . 'Content-Disposition: ' . $attdesc['disp'] . ';' . $this->_crlf . "\t" . 'filename="' . $attdesc['name'] . '"' . $this->_crlf . 'Content-ID: <' . $idarr[$attdesc['name']] . '>' . $this->_crlf . $this->_crlf . $this->_encodemsg($attdesc['source'], $attdesc['encode']);
                 }
                 $bval .= '--' . $boundary1 . '--';
             } elseif ($attachment) {
                 $hadd .= 'Content-Type: multipart/mixed;' . $this->_crlf . "\t" . 'boundary="' . $boundary1 . '"' . $this->_crlf;
                 $bval .= '--' . $boundary1 . $this->_crlf . $this->_ahtml[0] . $this->_crlf . $this->_crlf . $this->_encodemsg($vhtml, $this->_ahtml[1]) . $this->_crlf;
                 foreach ($this->_attach as $attdesc) {
                     $bval .= '--' . $boundary1 . $this->_crlf . 'Content-Type: ' . $attdesc['mime'] . $this->_crlf . 'Content-Transfer-Encoding: ' . $attdesc['encode'] . $this->_crlf . 'Content-Disposition: ' . $attdesc['disp'] . ';' . $this->_crlf . "\t" . 'filename="' . $attdesc['name'] . '"' . $this->_crlf . $this->_crlf . $this->_encodemsg($attdesc['source'], $attdesc['encode']);
                 }
                 $bval .= '--' . $boundary1 . '--';
             }
         }
         $hadd .= 'MIME-Version: 1.0';
         $hval1 .= $hadd;
         $hval2 .= $hadd;
     } else {
         if ($this->_atext) {
             $hval1 .= $this->_atext[0];
             $hval2 .= $this->_atext[0];
             $bval .= $this->_encodemsg($this->_atext[2], $this->_atext[1]);
         } else {
             $hval1 .= $this->_ahtml[0];
             $hval2 .= $this->_ahtml[0];
             $bval .= $this->_encodemsg($this->_ahtml[2], $this->_ahtml[1]);
         }
     }
     return array('header' => array('to' => $hto, 'local' => $hval1, 'client' => $hval2 . $this->_crlf . $this->_crlf), 'body' => $this->_splitmsg($bval));
 }