php mail attachment? problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tyrohansen
Forum Newbie
Posts: 8
Joined: Fri Apr 06, 2007 3:57 am

php mail attachment? problem

Post by tyrohansen »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hello there, my name is tyrohansen, a newbe to php. i current working on a script that sends an attachement to my email. fortunately it seems to work but the problem is "[b]I GET ONLY 1KB OF THE WHOLE FILE[/b]", can anyone show me how i can solve this.
this my source below:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
  <title></title>
</head>

<body>
 <?php

        $to = "tyrohansen@yahoo.com,";
        $from = "<webmaster@ventug.com>";
        $subject = "Here is your attachment";

        $fileatt = $HTTP_POST_FILES["userfile"]["tmp_name"];
        $fileatttype = $HTTP_POST_FILES["userfile"]["type"];
        $fileattname = $HTTP_POST_FILES["userfile"]["name"];

        $headers = "From: $from";

       //encoding
        $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}\"";

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

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

        $message .= "--{$mime_boundary}\n" .
                 "Content-Type: {$fileatttype};\n" .
                 " name=\"{$fileattname}\"\n" .
                 "Content-Disposition: attachment;\n" .
                 " filename=\"{$fileattname}\"\n" .
                 "Content-Transfer-Encoding: base64\n\n" .
                 $data . "\n\n" .
                 "--{$mime_boundary}--\n";

                      //sending email
                   if( mail( $to, $subject, $message, $headers ) ) {

            echo "<p>The email was sent.</p>";

        }
        else {

            echo "<p>There was an error sending the file.</p> <br>$fileattname";

        }

?>

</body>

</html>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I don't see where you collect the file contents into $data.

Have you looked at Swift Mailer:

http://www.swiftmailer.org/
http://www.swiftmailer.org/wikidocs/v3/ ... ttachments
Post Reply