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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Leon

    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_fr om;

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

    $semi_rand = md5(time());
    $mime_boundary = "==Multipart_Bo undary_x{$semi_ rand}x";

    $headers .= "\nMIME-Version: 1.0\n" .
    "Content-Type: multipart/mixed;\n" .
    " boundary=\"{$mi me_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(bas e64_encode($dat a));

    $email_message .= "--{$mime_boundary }\n" .
    "Content-Type: {$fileatt_type} ;\n" .
    " name=\"{$fileat t_name}\"\n" .
    //"Content-Disposition: attachment;\n" .
    //" filename=\"{$fi leatt_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,
  • Manuel Lemos

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

    Hello,

    On 10/06/2003 05:28 AM, Leon wrote:[color=blue]
    > 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?[/color]

    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:



    --

    Regards,
    Manuel Lemos

    Free ready to use OOP components written in PHP
    Free PHP Classes and Objects 2025 Versions with PHP Example Scripts, PHP Tutorials, Download PHP Scripts, PHP articles, Remote PHP Jobs, Hire PHP Developers, PHP Book Reviews, PHP Language OOP Materials


    Comment

    Working...