in reply to Send an email attachment

The error message basically says that you didn't specify a recipient.

You do have a $smtp->to Statement in your code, but it has to come before any ->data or ->datasend call. Best put it right after the $smtp->mail call.