Here's an example I did for folks at work to illustrate sending attachments. I added functionality to do what you are trying to do. This works using ksh on Solaris. Just replace the variables in the constants section. Hope it helps you:
#!/bin/ksh
##
## mailtest - example to show how to do attachments.
##
# Set constants
typeset -r MAILBODY="This is the body of the e-mail"
typeset -r FILEPATH=/dir1/subdir1
typeset -r FILESPEC=*.sh
typeset -rx SINGLEFILE=set_example.sh
typeset -r MAILADDR=name@domain.com
# convert CR/LF so it will open properly in Outlook.
# only need this if CR/LFs are not being translated properly.
unix2dos -437 -ascii $SINGLEFILE attach.out
if (( $? != 0 ))
then print "$0: unix2dos failed"
exit 1
fi
#
# Attach one file.
#
(print $MAILBODY; uuencode attach.out $SINGLEFILE) | \
mailx -s "mail example 1 attachment" $MAILADDR
if (( $? != 0 ))
then print "$0: uuencode or mailx failed"
exit 2
fi
#
# Attach the file twice by specifying explicitly.
#
(print $MAILBODY; uuencode attach.out ${SINGLEFILE}; uuencode attach.out ${SINGLEFILE}) | \
mailx -s "mail example 2 attachments" $MAILADDR
if (( $? != 0 ))
then print "$0: uuencode or mailx failed"
exit 3
fi
#
# Attach multiple files by specifying a filespec.
#
( print $MAILBODY;
for filename in ${FILEPATH}/${FILESPEC}
do
uuencode $filename $(basename $filename)
done) | mailx -s "multiple attachments via filespec" $MAILADDR
if (( $? != 0 ))
then print "$0: uuencode or mailx failed"
exit 4
fi
exit 0
Is it possible you are getting badly formed filenames returned or files with spaces in them from *.txt? Do an ls -l on *.txt and make sure you are getting what you expect.