DamienRoche Posted August 6, 2008 Share Posted August 6, 2008 Whoa, I didn't think it would be this hard to attach a simple file to an email. I can do everything BUT this. I know there is a function: add_attachment() But I can't get it to work. I have tried to use phpMailer, oh no...I don't ever want to see that script again. Can anyone recommend a simple way to attach files to emails? Here is some code I was using: $fileatt = "uploads/image.gif"; $fileatttype = "image/gif"; $fileattname = "image_sent.gif; //can be named anything. $file = fopen( $fileatt, 'rb' ); $data = fread( $file, filesize( $fileatt ) ); fclose( $file ); $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $semi_rand = md5( time() ); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $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"; mail ($email, $subject, $message, $headers); Yet when I receive the email, there is no attachment and inside it where the $data variable is called there is nothing but an orgasm of dreadfully depressing characters. Can anyone shed some light on what I've missed? Thanks. Link to comment https://forums.phpfreaks.com/topic/118388-simple-way-to-attach-file-to-email-using-mime/ Share on other sites More sharing options...
DamienRoche Posted August 6, 2008 Author Share Posted August 6, 2008 I'll only bump once. Can anyone here recommend how I should approach this? Thanks. Link to comment https://forums.phpfreaks.com/topic/118388-simple-way-to-attach-file-to-email-using-mime/#findComment-610199 Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 Wait, why don't you like phpMailer? Link to comment https://forums.phpfreaks.com/topic/118388-simple-way-to-attach-file-to-email-using-mime/#findComment-610203 Share on other sites More sharing options...
DamienRoche Posted August 6, 2008 Author Share Posted August 6, 2008 I can't use it. I just can't get my head around it. I have tried to configure it, but it just won't work. Can you advise, a little, how I would attach a doc using phpMailer. Much obliged. Link to comment https://forums.phpfreaks.com/topic/118388-simple-way-to-attach-file-to-email-using-mime/#findComment-610227 Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 The addAttachment() method does it for you. Just specify a path to the file. Link to comment https://forums.phpfreaks.com/topic/118388-simple-way-to-attach-file-to-email-using-mime/#findComment-610230 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.