Why won't my attached PDF go through ??

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ave,

I created a form which can accept 2 file attachments and send an HTML
Email... Everything works great... The files even get attached and sent, the
ONLY problem is... The PDF file I'm sending attached open up empty! They are
all blank.. Like everything has been wiped off from them!!

Here's my code.. 

<form action=<?php echo $PHP_SELF ?> method=post
ENCTYPE="multipart/form-data" name="f1" id="f1" >
            <table>
              <tr>
                <td align="left" valign="middle" class="style13">From
(Name):</td>
                <td><input name=from_name type=text value="Gerson Bullock"
size="40"></td>
              </tr>
              <tr>
                <td align="left" valign="middle" class="style13">From
(Email):</td>
                <td><input name=from type=text
value="gerson@xxxxxxxxxxxxxxxxxxxx" size="40"></td>
              </tr>
              <tr>
                <td align="left" valign="middle" class="style13">To
(First,Last):</td>
                <td><input name=to_nameF type=text id="to_nameF" size="15">
                <input name=to_nameL type=text id="to_nameL" size="15"></td>
              </tr>
              <tr>
                <td align="left" valign="middle" class="style13">To
(Email):</td>
                <td><input name=to type=text size="40"></td>
              </tr>
              <tr>
                <td align="left" valign="middle"
class="style13">Subject:</td>
                <td><input name=subject type=text value="Your Conversation
with Gerson Bullock" size="40"></td>
              </tr>
              <tr>
                <td align="left" valign="top" class="style13">Message:</td>
                <td><textarea name=message_html cols="35" rows="4">
                <b>Test Message</b>
                </textarea></td>
              </tr>
              <tr>
                <td align="left" valign="middle" class="style13">Attachment
1 </td>
                <td><input type=file name=file1></td>
              </tr>
              <tr>
                <td align="left" valign="middle" class="style13">Attachment
2 </td>
                <td><input type=file name=file2></td>
              </tr>
            </table>
            <input name="doSubmit" type=submit id="doSubmit" value=Send Mail
Mail>
          </form>

<?php
$message_html = stripslashes($message_html);
  $m = new CMIMEMail("$to_nameF $to_nameL <$to>","$from_name
<$from>",$subject);
             $m->mailbody($message_html, $message_html);
             if( $file1) {
                $m->attachFile_raw($file1,$file1_name,$file1_type);
             };
             if( $file2)
{$m->attachFile_raw($file2,$file2_name,$file2_type);};
             $m->send();
?>

<?php
/*
* $m = new CMIMEMail($to,$from,$subject);
* $m->mailbody("This is simply text","<html><body><h1>This is HTML
text</h1>");
* $m->attach("example.html","text/html",$filebody);
* $m->attachFile("resume.gif","image/gif");
* $m->send();
*/

class CMIMEMail {
 var $to;
 var $boundary;
 var $smtp_headers;
 var $filename_real;
 var $body_plain;
 var $body_html;
 var $atcmnt;
 var $atcmnt_type;
 
 function CMIMEMail($to,$from,$subject,$priority=3) {
   $this->to=$to; $this->from=$from;
   $this->subject=$subject; $this->priority=$priority;
   $this->boundary="----=_NextPart_".time()."_".md5(time())."_";
 }
 function  mailbody( $plain, $html="" ) {
   $this->body_plain=$plain;
   $this->body_html=$html;
 }
 function  attach( $name, $content_type, $data ) {
 }
 function  attachfile_raw( $fname, $mailFileName, $content_type ) {
   if($f=@fopen($fname,"r")) {
    $this->atcmnt[$mailFileName]=fread($f,filesize($fname));
    $this->atcmnt_type[$mailFileName]=$content_type;
    fclose($f);
  } 
 }
 function  attachfile( $fname, $content_type ) {
    attachfile_raw($fname,$fname,$content_type);
 }
 function  clear() {
   unset( $atcmnt );
   unset( $atcmnt_type );
 }
 function  makeheader() {
   $out ="From: ".$this->from."\n";
   $out.="Reply-To: ".$this->from."\n";
   $out.="MIME-Version: 1.0\n".
    "Content-Type: multipart/mixed;\n\t boundary=\"".$this->boundary."\"\n".
        "X-Priority: ".$this->priority."\n".
        "X-Mailer: phpMimeMail ( http://www.informed-sources.com/ )\n";
   return $out;
 }
 function  makebody() {
   $boundary2= "----=_NextAttachedPart_".time()."_".md5(time()+101)."_";
   $out="";
   if( " ".$this->body_html!=" " ) {
     $out="\nThis is a multi-part message in MIME format.\n\n";
     $out.="--".$this->boundary."\nContent-Type:
multipart/alternative;\n\tboundary=\"$boundary2\"\n";
     $out.="$body_plan\n".
       "--$boundary2\nContent-Type: text/plain\n".
#       "Content-Disposition: inline\n".
       "Content-Transfer-Encoding: quoted-printable\n\n".
       $this->body_plain.
       "\n\n--$boundary2\n".
       "Content-Type: text/html\n".
#       "Content-Disposition: attachment;\n\tfilename=\"message.html\"\n".
           "Conent-Transfer-Encoding: quoted-printable\n".
       "\n$this->body_html\n\n".
       "--$boundary2--\n";
   } else {
     $out="\n\n".$this->body_plain."\n\n";
     $out.="--".$this->boundary."\n".
    "Content-Type: text/plain\n".
    "Content-Transfer-Encoding: quoted-printable\n\n".
    $this->body_plain.
    "\n\n--".$this->boundary.
    "\n";
   }
   if( is_array( $this->atcmnt_type ) ) {
     reset( $this->atcmnt_type);
     while( list($name, $content_type) = each($this->atcmnt_type) ) {
       $out.="\n--".$this->boundary."\nContent-Type:
application/pdf\nContent-Transfer-Encoding: base64\nContent-Disposition:
attachment; filename=\"$name\"\n\n".
         chunk_split(base64_encode($this->atcmnt[$name]))."\n";
     }   
   }
   $out.="\n--".$this->boundary."--\n";
   return $out;
 }
 function  send(){
   mail( $this->to, $this->subject, $this->makebody(),$this->makeheader() );
   echo "<b><i><small><Mail Sent Successfully</b></i></small>";
 }
}

?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux