in reply to Getting input to mailx

Why write unportable and broken code? Just use Mail::Send. It can internally use both mailx, sendmail or SMTP connect for emails while having exactly same interface.