I tested it before I post, as I always do. I believe the problem is that you didn't replace the email server name and email address with real ones.
The error you got basically means that $smtp is undef. I believe that is because you didn't change my dummy server name to your real one, so Perl can not establish the SMTP connection.