Professional Web Applications Themes

email attachment cannot be opened - PHP Development

hi, I've made a form to send out emails with attachments, and the attachments look ok when they arrive but the content is somehow bad. I cannot open gifs nor can word open the doents. Looking at the content something may be wrong with the encoding: if i open the GIF file the normal one as well as the attachment I sent start with GIF89a, but then they start to be different. I think this is the relevant part of my code: $atta_type=$_FILES['AttachedFile']['type']; if (strpos($atta_type,';')){$atta_type=substr($atta_t ype,0,strpos($atta_type,';'));} //for Opera $atta_tmp_name=$_FILES['AttachedFile']['tmp_name']; $fp = fopen($atta_tmp_name,"rb"); while (!feof($fp)){ $filedata .= addslashes(fread($fp,1200));} $filedata = chunk_split(base64_encode($filedata)); ...

  1. #1

    Default email attachment cannot be opened

    hi,
    I've made a form to send out emails with attachments, and the attachments
    look ok when they arrive but the content is somehow bad. I cannot open gifs
    nor can word open the doents. Looking at the content something may be
    wrong with the encoding: if i open the GIF file the normal one as well as
    the attachment I sent start with GIF89a, but then they start to be different.
    I think this is the relevant part of my code:


    $atta_type=$_FILES['AttachedFile']['type'];
    if
    (strpos($atta_type,';')){$atta_type=substr($atta_t ype,0,strpos($atta_type,';'));}
    //for Opera
    $atta_tmp_name=$_FILES['AttachedFile']['tmp_name'];

    $fp = fopen($atta_tmp_name,"rb");
    while (!feof($fp)){ $filedata .= addslashes(fread($fp,1200));}

    $filedata = chunk_split(base64_encode($filedata));

    $attachment = $atta_type."\n\n"
    ."--$boundary\n"
    ."Content-Type: $atta_type"."; name = \"$atta_name\"\n"
    ."Content-Transfer-Encoding: $encoding"
    ."\n\n$filedata\n\n"
    ."--$boundary--\n";

    Just for fun the headers as well:

    'From: "SENSE mailinglist" <mailinglistsense.nl>'
    'Subject: '.$subject
    'Reply-To: [email]mailinglist_replysense.nl[/email]'
    'Return-Receipt-To: [email]mailinglist_return_receiptsense.nl[/email]'
    'Return-Path: [email]mailinglist_returnedsense.nl[/email]'
    'MIME-Version: 1.0'
    'Content-Type: multipart/mixed;
    boundary="'.$boundary."\"\n\n");////'To: SENSE_List'

    "This is a MIME encoded message. \n\n"
    ."--$boundary\n"
    ."Content-Type: ".(($IsHTML)?'text/html':'text/plain')."\n"
    ."Content-Transfer-Encoding: 8bit\n\n"
    .$mailbody .$message



    Chris Hayes Guest

  2. #2

    Default Re: [PHP] email attachment cannot be opened (solved)

    I found the culprit!
    I copied the filereading part without checking too good, and it had an
    "addslashes" call which ruined the file content very professionaly.
    Chris Hayes Guest

Similar Threads

  1. Question how to send email with attachment in php
    By Unregistered in forum Brainstorming Area
    Replies: 0
    Last Post: December 13th, 01:26 PM
  2. folder email attachment
    By kyle969 in forum Coldfusion - Advanced Techniques
    Replies: 1
    Last Post: June 9th, 02:23 PM
  3. email attachment...
    By Carl Nielsen in forum PHP Development
    Replies: 2
    Last Post: November 29th, 02:00 PM
  4. Embedded email attachment
    By Tony S in forum FileMaker
    Replies: 2
    Last Post: September 9th, 06:25 PM
  5. Email attachment
    By Wald in forum PHP Development
    Replies: 4
    Last Post: July 9th, 02:59 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139