on 2/1/02 11:36 AM, Dave at [EMAIL PROTECTED] wrote:

> How can I add an attachment to an email using MAIL().  So far I have been
> able to successfully send email by using:
> mail($to, $subject, $message, $headers);
> Is there something I can add in the $headers to add an attachment??????

you really want to read the rfc for this. i think it is 821. google for
'smtp rfc' and you should be able to find it.

here is a function i wrote when i was first learning php, and i'm sure it
can be cleaned up, but it usually works for me.

hope it helps,

ssage="") {

    if ($attachmentType=="") $attachmentType = "text/plain;

    $timestring = md5(time());
    $seperator = "NextPart_$timestring";
    $header = "MIME-Version: 1.0\nContent-Type: multipart/mixed;\n
    this is some extra text that should be ignored. if you can read this,
    perhaps you should upgrade your email program.\n";

    if ($filename !="") { $attachpreface = "
Content-Type: $attachmentType;
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
    } else { $attachpreface = "
Content-Type: $attachmentType
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment";

    $messagepreface = "
Content-Type: text/plain; charset=US-ASCII";
    $attachment = "$attachpreface\n\n"."$attachment"."\n--$seperator";

    if ($message != "") {
        $message = "$messagepreface\n\n"."$message"."$attachment";
    } else {
        $message = "$attachment";

//    echo "$header\n$message\n";
    mail ($to,$subject,$message,$header);

PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to