Add a custom SMTP port option in the cgi config file.
A Perl module is used to construct the mail and needs to get the port value from the config file.
(like it already does for the SMTP server, username and password)
Both files in attachment.
I can update / fix your code in couple of hours and all I need to start is milestone payment from you.
You'll release it only after you check everything on your side.
Thanks.
Roman