use MIME::Base64; $smtp->data(); $smtp->datasend( "\nSubject: $subj \nMIME-Version: 1.0" ); $smtp->datasend( "\nContent-Type: multipart/mixed;boundary=\"Bb0uNddArray\"" ); $smtp->datasend( "\n--Bb0uNddArray" ); $smtp->datasend( "\nContent-type: text/plain" ); $smtp->datasend( "\n\n$msg\n\n" ); # plaintext body if( $attachement ) { $smtp->datasend( "--Bb0uNddArray" ); $smtp->datasend( "\nContent-Type: $content_type; name=\"$filename\"" ); $smtp->datasend( "\nContent-Transfer-Encoding: base64\n\n" ); while ( read( $file, $buff, 512 ) { $smtp->datasend( encode_base64($buff) ) || die"cant encode: $!"; } } # if attachement $smtp->datasend( "\n\n--Bb0uNddArray--" ); # send this even if theres no attachment $smtp->dataend(); $smtp->quit;