You receive an authentication error when the script connects to your gmail account. In this case please try the solution below:
1. You have to allow pop3 and/or imap in your google account under the tab "forwarding and pop/imap".
2. You have to allow insecure apps:
Here you see also the error messages from google.
3. You have to activate your insecure website
But pay attention that you are logged in with the correct google account, before you do this. You can't check this on the above site.