SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict Caryn's Avatar
    Join Date
    Aug 2002
    Location
    Sydney, Australia
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sending Gibberish to Mozilla Email User

    I'm trying to send an email form (with an attachment) using PHP, but my client (who's X-Mailer looks like this: Mozilla 4.74 [en] (Win98; U)) keeps receiving it as gibberish.

    I've tried sending it to myself and testing it with Eudora and Outlook and it looks fine, so what do I have to do to this code to make it send an attachment to Mozilla users?

    PHP Code:
    if($submit)
    {
    $subject $title." - ".$job_ref;
    $sendto "xxxxx";
    $replyto "xxxxx";
    $message $name." is applying for job no: ".$job_ref." - ".$title."\n\n";
    $message .= $name."'s phone number is: ".$client_phone."\n\n";
    $message .= "Here is ".$name."'s job application letter:\n\n".$app_letter."\r\n";
    $from $client_email;
    $filename $fileatt_name;
    $mimetype $_FILES['fileatt']['type'];

      class 
    CMailFile {
       var 
    $subject;
       var 
    $addr_to;
       var 
    $text_body;
       var 
    $text_encoded;
       var 
    $mime_headers;
       var 
    $mime_boundary "--==================_846811060==_";
       var 
    $smtp_headers;
       
       function 
    CMailFile($subject,$to,$from,$msg,$filename,$mimetype "application/octet-stream"$mime_filename false) {
        
    $this->subject $subject;
        
    $this->addr_to $to;
        
    $this->smtp_headers $this->write_smtpheaders($from);
        
    $this->text_body $this->write_body($msg);
        
    $this->text_encoded $this->attach_file($filename,$mimetype,$mime_filename);
        
    $this->mime_headers $this->write_mimeheaders($filename$mime_filename);
       }
      
       function 
    attach_file($filename,$mimetype,$mime_filename) {
        
    $encoded $this->encode_file($filename);
        if (
    $mime_filename$filename $mime_filename;
        
    $out "--" $this->mime_boundary "\n";
        
    $out $out "Content-type: " $mimetype "; name=\"$filename\";\n";  
        
    $out $out "Content-Transfer-Encoding: base64\n";
        
    $out $out "Content-disposition: attachment; filename=\"$filename\"\n\n";
        
    $out $out $encoded "\n";
        
    $out $out "--" $this->mime_boundary "--" "\n";
        return 
    $out
      
    // added -- to notify email client attachment is done
       
    }
      
       function 
    encode_file($sourcefile) {
        if (
    is_readable($sourcefile)) {
         
    $fd fopen($sourcefile"r");
         
    $contents fread($fdfilesize($sourcefile));
         
    $encoded my_chunk_split(base64_encode($contents));
         
    fclose($fd); 
        }
        return 
    $encoded;
       }
      
       function 
    sendfile() {
        
    $headers $this->smtp_headers $this->mime_headers;  
        
    $message $this->text_body $this->text_encoded;
        
    mail($this->addr_to,$this->subject,$message,$headers);
       }
      
       function 
    write_body($msgtext) {
        
    $out "--" $this->mime_boundary "\n";
        
    $out $out "Content-Type: text/plain; charset=\"us-ascii\"\n\n";
        
    $out $out $msgtext "\r\n\r\n";
        return 
    $out;
       }
      
       function 
    write_mimeheaders($filename$mime_filename) {
        if (
    $mime_filename$filename $mime_filename;
        
    $out "MIME-version: 1.0\n";
        
    $out $out "Content-type: multipart/mixed; ";
        
    $out $out "boundary=\"$this->mime_boundary\"\n";
        
    $out $out "Content-transfer-encoding: 7BIT\n";
        
    $out $out "X-attachments: $filename;\n\n";
        return 
    $out;
       }
      
       function 
    write_smtpheaders($addr_from) {
        
    $out "From: $addr_from\n";
        
    $out $out "Reply-To: $addr_from\n";
        
    $out $out "X-Mailer: PHP3\n";
        
    $out $out "X-Sender: $addr_from\n";
        return 
    $out;
       }
      }
      
    $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filename,$mimetype);
    $mailfile->sendfile();  
      
      if (
    $mailfile) {
      echo 
    "Your message has been sent.";
      echo 
    "<p><b><a href=""index.php>Back to the joblistings</a></b></p>\n"
      } else {
      echo 
    "Please make sure you include your name, email address, and phone number.<br>\n"
      echo 
    "<p><b><a href=""index.php>Back</a></b></p>\n"
      }


  2. #2
    SitePoint Addict Caryn's Avatar
    Join Date
    Aug 2002
    Location
    Sydney, Australia
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any experts out there that can help?

  3. #3
    SitePoint Addict Caryn's Avatar
    Join Date
    Aug 2002
    Location
    Sydney, Australia
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does anyone know what's going on with the above code?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •