sending mail from perl using mailx

hi All,

i am trying to send a mail from perl using mailx.
the script runs fine if i hard code the file path which is to be attached to the mail. but when i give a variable containing the path of the file , perl is not able to send the file.

ex:

system('uuencode /attach/test.txt test.txt | mailx -s "Control File" -r abc@mno.com xyz@mno.com');

in the above case the scripts works fine.

system('uuencode $file $file | mailx -s "Control File" -r abc@mno.com xyz@mno.com');

here $file contains the file path /attach/test.txt .
In this case the script sends a mail but then mail doesnt have the attachment.

Please advice.

Thanks,
Mahi

another approach that you may try is use CPAN module MIME::Lite

The issue is your using single quotes so it is not interpreting your variables. Change the single quotes to double quotes and try escaping the double quotes in the command line like \". So the line might read

system("uuencode /attach/test.txt test.txt | mailx -s \"Control File\" -r abc@mno.com xyz@mno.com");

Err meant this line

system("uuencode $file $file | mailx -s \"Control File\" -r abc@mno.com xyz@mno.com");

you may have the escape the @ sign too depending on the OS.