php / mail / attachment - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

php / mail / attachment

HaileHaile Posts: 9Member
Hello,

I have a form and i set this data into a XML file.
Now i want to sent this file as attachment to my e-mail adres.

But how can i do this?

Regards en thanks,

Comments

  • tvientitvienti Posts: 230Member
    : Hello,
    :
    : I have a form and i set this data into a XML file.
    : Now i want to sent this file as attachment to my e-mail adres.
    :
    : But how can i do this?
    :
    : Regards en thanks,

    I haven't tested this but it should get you on the right track. Google "php mail attachment" and you can probably find plenty of info.

    [code]
    function sendAttachment($to, $from, $subject, $message, $path_to_attachment, $filename, $MIME_type)
    {
    /* do error checking here to make sure file exists, is readable, ... */
    $full_path = "$path_to_attachment/$filename";
    $size = filesize($full_path);
    $attachment = chunk_split(base64_encode(file_get_contents($full_path)));
    $boundary = uniqid();

    /* do input cleaning here to make sure nobody's attempting a header injection */

    /* send the message */
    $headers = array();
    $headers[] = "From: $from
    ";
    $headers[] = "Content-Type: multipart/mixed; boundary="$uid"

    ";
    $headers[] = "This is a multi-part message in MIME format.
    ";
    $headers[] = "--$boundary
    ";
    $headers[] = "Content-Type: text/plain; charset=iso-8859-1
    ";
    $headers[] = "Content-Transfer-Encoding: 7bit

    ";
    $headers[] = "$message

    ";
    $headers[] = "--$uid
    ";
    $headers[] = "Content-Type: $MIME_type; name="$filename"
    ";
    $headers[] = "Content-Transfer-Encoding: base64
    ";
    $headers[] = "Content-Disposition: attachment; filename="$filename"

    ";
    $headers[] = "$content

    ";
    $headers[] = "--$uid--";
    $header = implode('', $headers);

    /* add pass/fail checks here too */
    mail($to, $subject, "", $header);
    }
    [/code]
Sign In or Register to comment.