Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts

    Sending Attachements

    I'm trying to send an attachment with an email and the attachement is recieved but its not openable. I've tried sending to yahoo and to my domain email and both have the same problem.

    PHP Code:
    function sendAttached($to$subject$msgtext$from$file$type)
    {
    $fp fopen($file,"rb");

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

    PHP Code:
    sendAttached('me@mydomain.com''Test''Please find attached... something '$from$path.$filename"text/plain"$filename); 

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    I didn't test this out, but I thought it was a good tutorial on the subject ...

    http://www.hollowearth.co.uk/tech/ph...ttachments.php

  • #3
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    I tried checked that against what I had and there were a few extra line breaks which I've put in now and its still not working :s

  • #4
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,092
    Thanks
    2
    Thanked 23 Times in 23 Posts
    One of the things that might help is to send yourself an email with an attacment, just as you normally would in Outlook or whatever email client you use. Look at the message source which includes the headers, and see how that differs from the one you're trying to work with here.

    Another option might be to use PHPMailer.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #5
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    I tried that too and it all looks fine... I tihnk I'm going to have to go through this with a fine tooth comb, theres obviously some minor difference here that I'm not spotting.

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Nancy ...

    Make a copy of your script and save as .txt ... then attach it here.

    I'm thinking there's still a broken line (with carriage return), but we can't
    see it with this forum. So we need to see your actual file.

  • #7
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    I found another script and thats working fine. Interestingly, it skips the part about Content-Disposition: attachment;


  •  

    Posting Permissions

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