A man gets an erection when he is sexually aroused or spontaneously (for example during a wet dream). The penis becomes erect.