We will be using a module to send emails. A module is a package of code that is tested to work very well, is reviewed by the coder community, and approved for distribution for others to use in their code. The module we'll be using is `Email::Mailer`, and you will add this to the list of modules you have at the top of your file; ```perl #the full list include the shebang at the top, and one more like... use Email::Mailer; ``` The `Email::Mailer` module uses a hash to send the email. Theoretically this could mean that if you have already parsed your data into a `%USERDATA` hash or similar, you could just pass that hash like this; ```perl Email::Mailer->send(%USERDATA); ``` However, if there is *any* other data aside from - the email address of the recipient - the email address of the person sending the email - the subject - the body of the email message in the `%USERDATA` hash, or if any one of those are missing, the `Email::Mailer->send` command will fail. Also, if any of the keys in your hash are not named the way the `Email::Mailer->send` command expects (for example, you called the body of the email `'content'` instead of `'text'`), it will also fail. Therefore it is recommended that you spell out the hash with *exactly* the data you want to send, like in the example below (don't forget, PERL is case-sensitive); ```perl Email::Mailer->send( to => '[email protected]', from => '[email protected]', subject => "Can have a $USERDATA{$variable} in it", text => $USERDATA{'body'}, ); ``` Alternatively you can precreate the hash, like so; ```perl %emailContent = (); $emailContent{'to'} = '[email protected]'; $emailContent{'from'} = '[email protected]'; $emailContent{'subject'} = "Can have a $USERDATA{$variable} in it"; $emailContent{'text'} = $USERDATA{'body'}; Email::Mailer->send(%emailContent); ``` # Reporting Success (or Failure) Once you issue the `Email::Mailer->send` command, you can then report to your user that the email has been sent. This is easily done by simply issuing a `print` command with a success message like `<h1>Email Sent Successfully!</h1>`. However, what if it didn't send successfully? We need to determine why. This is where the `die` command can be quite useful. The `die` command will kill your script, not letting another command be run. This is very useful in many cases, as if your script has an error, you don't want that error to create a domino-effect through your code, so killing your code is a safety mechanism. ```perl Email::Mailer->send(%emailContent) or die; ``` You can also create your own `die` subroutine, but you have to call it something different. ```perl Email::Mailer->send(%emailContent) or &dieNice($!); sub dieNice { ($systemError) = @_; print "<h1>Aw puddin', somefing go wong?</h1>\n"; print "Error from system: $systemError\n"; print "</body></html>\n"; } ``` The `&dieNice` call above sends the `$!`, which is a universal scalar variable for the most recent error experienced. It is sent to the subroutine and renamed `$systemError`. This is a nicer way of getting an error report (sometimes the `die` message looks scary).