in reply to CGI form to email

It's not easy. There are security considerations. Why don't you use the one from NMS, and modify it if need be.