GPG is always returning 2 at the result. My code is as follows
$cmd = \"/usr/bin/gpg -a --recipient $to -e -o $outfile $infile\";
Where outfile
You also might want to concider adding key to trusted keys list:
gpg.exe --edit-key KEY_NAME trust 5 (level of trust) Y Save
I've had some problems of --always-trust parameter not functioning properly on XP windows, this helped me solve the problem.
--always-trust