emailing with an attachment that has fetched from db (longblob)

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default emailing with an attachment that has fetched from db (longblob)

    I am trying to send an email with an attachment.
    The problem is the attachment is stored in db where I have created a
    longblob field that contains the file so I have no idea how to specify
    the file path when I want to send an email.
    I have tried "" and "/" that didn't work.
    Any help?

    My code is

    ------------------------------------------------------------------------


    $fileatt = ""; // Path to the file
    $fileatt_type = "text/html"; // File Type
    $fileatt_name = "AttachFilename.txt"; // Filename that will be used
    for the file as the attachment

    $email_from = ""; // Who the email is from
    $email_subject = "Testing"; // The Subject of the email
    $email_txt = "how are you?"; // Message that the email has in it
    $message_text = ""; // Message that the email has in it

    $email_to = ""; // Who the email is too

    $headers = "From: ".$email_from;

    $file = fopen($fileatt,'rb');
    $data = fread($file,filesize($fileatt));
    fclose($file);

    $semi_rand = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

    $headers .= "\nMIME-Version: 1.0\n" .
    "Content-Type: multipart/mixed;\n" .
    " boundary=\"{$mime_boundary}\"";

    $email_message = "This is a multi-part message in MIME format.\n\n" .
    "--{$mime_boundary}\n" .
    "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
    "Content-Transfer-Encoding: 7bit\n\n" .
    $message_text . "\n\n";

    $data = chunk_split(base64_encode($data));

    $email_message .= "--{$mime_boundary}\n" .
    "Content-Type: {$fileatt_type};\n" .
    " name=\"{$fileatt_name}\"\n" .
    //"Content-Disposition: attachment;\n" .
    //" filename=\"{$fileatt_name}\"\n" .
    "Content-Transfer-Encoding: base64\n\n" .
    $data . "\n\n" .
    "--{$mime_boundary}--\n";

    $ok = @mail($email_to, $email_subject, $email_message, $headers);



    -------------------------------------------------------------------------


    Thanks a lot in advance,
    Leon Guest

  2. Similar Questions and Discussions

    1. #39440 [NEW]: Custom IMAP flags cannot be fetched
      From: loikiolki at yahoo dot ca Operating system: Windows XP PHP version: 5.2.0 PHP Bug Type: Feature/Change Request Bug...
    2. Problem on inserting data in a LONGBLOB field
      Hi all, I try to insert data in a LONGBLOB field. Usually it doesn't matter, but depending on which server I execute the query, it fails....
    3. Fetched text looses layout...how can I keep it?
      Hi! Here's the problem. I have a comments textfield in my insert form. There ppl can type any kind of text, say for example: Hello! Cool site...
    4. Extension for emailing attachment?
      I am looking for a dreamweaver extension (php) that will allow the visitor to attach a file to a form for e-mailing. Ideally, the extension will...
    5. emailing an attachment
      Greetings, I'm looking for some help sending an e-mail attachment via a perl CGI. I'm an experienced programmer, but a Perl moron. Previous...
  3. #2

    Default Re: emailing with an attachment that has fetched from db (longblob)

    Hello,

    On 10/06/2003 05:28 AM, Leon wrote:
    > I am trying to send an email with an attachment.
    > The problem is the attachment is stored in db where I have created a
    > longblob field that contains the file so I have no idea how to specify
    > the file path when I want to send an email.
    > I have tried "" and "/" that didn't work.
    > Any help?
    You may want to try this class that lets you compose messages with
    attachements defined with data taken from strings. It comes with an
    example that lets you define the file name to whatever you want:

    [url]http://www.phpclasses.org/mimemessage[/url]

    --

    Regards,
    Manuel Lemos

    Free ready to use OOP components written in PHP
    [url]http://www.phpclasses.org/[/url]

    Manuel Lemos Guest

Posting Permissions

  • You may not post new threads
  • You may 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