PHP 4.1.1 and Email Attachments

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sylence
    New Member
    • May 2007
    • 3

    PHP 4.1.1 and Email Attachments

    Now I've been working on a script that sends emails with different attachments, including csv, xls, docs, txt, and html/htm files. However when attaching, some information at the top in the txt files are missing, and not only that, doc / xls files are unable to open without a slew of funny characters when running through [PHP]chunk_split(bas e64_encode($fil ename))[/PHP] to attach. The attachment is there, the message is there. However opening the applications is a whole different story! The script is below. My suspicion is I'm using a very a outdated version of PHP (hopefully will be upgraded soon!). Could this be the culprit? Otherwise, I'm stumped on the inconsistent handling of attachments using PHP.

    [PHP]

    if (preg_match("/\.(txt)$/",$filename ) ) { $mimetype = "text/txt";
    } else if ( preg_match("/\.(csv)$/",$filename ) ) { $mimetype = "text/csv";
    } else if ( preg_match("/\.(htm)$/",$filename ) ) { $mimetype = "text/htm";
    } else if ( preg_match("/\.(html)$/",$filename ) ) { $mimetype = "text/html";
    } else if ( preg_match("/\.(doc)$/",$filename ) ) { $mimetype = "applicatio n/vnd.ms-word";
    } else if ( preg_match("/\.(xls)$/",$filename ) ) { $mimetype = "applicatio n/vnd.ms-excel";
    } else { $mimetype = "text/txt"; }


    function sendmsg($to, $subject, $msgtext, $from, $file, $type)
    {

    // $fp = fopen($file,"r" );
    // $fcontent = fread($fp ,filesize($file ));
    // fclose($fp);
    // $content = chunk_split(bas e64_encode($fco ntent));
    $sep = strtoupper(md5( uniqid(time())) );
    $name = basename($file) ;
    $header = "From: $from\nReply-To: $from\n";
    $header .= "MIME-Version: 1.0\n";
    $header .= "Content-Type: multipart/mixed; boundary=$sep\n ";
    $body .= "--$sep\n";
    $body .= "Content-Type: text/plain\n";
    $body .= "Content-Transfer-Encoding: 8bit\n\n";
    $body .= "$msgtext\n ";
    // $body .= "--$sep\n";
    // $body .= "Content-Type: $type; name=\"$file\"\ n";
    // $body .= "Content-Transfer-Encoding: base64\n";
    // $body .= "Content-Disposition: attachment; filename=\"$fil e\"\n";
    // $body .= "$content\n ";
    $body .= "--$sep--";
    if (mail($to, $subject, $body, $header)) {
    return true;
    } else {
    return false;
    }
    }

    sleep(0.25);
    sendmsg($recipi ent, $subject, $contact_info, $froms_, $target_path, $mimetype);

    [/PHP]

    Yes the attachment code is now commented because I have it working to send emails only with a link to the document instead of an attachment. But All i did was comment out instead of rewrite code. BIGUPS and appreciation!
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    I think you will need another newline before the content.

    Comment

    • sylence
      New Member
      • May 2007
      • 3

      #3
      Originally posted by Motoma
      I think you will need another newline before the content.
      Jeezz, you are correct. Lesson learned! thnx

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by sylence
        Jeezz, you are correct. Lesson learned! thnx
        No problem. Welcome to The Scripts.

        Comment

        Working...