1

I want my users to get an email when they login for the first time. I am thinking to create an array to store userids that have logged in before. When users login, compare their userid with the array, if it is in the array then do nothing, if not then add the id into the array and proceed to generate email. The question is, where is the best place to do this comparison? I am thinking it should be right after a user logs in and find this onUserAfterLogin event on https://docs.joomla.org/Plugin/Events/User. But how do I use it? And should I categorize what I want to do as a plugin?

1 Answer 1

1

Yes, writing a plugin and leveraging the onUserAfterLogin event seems like the best way.

As for how to check for the first visit:

  1. You can check the user's lastvisitDate column for a 0000-00-00 00:00:00 value as discussed in this Joomla Forum Thread: First login redirect plugin. However, if there was an error in delivering the email, you will need to add a consideration for how you want to be alerted of the failure.

  2. You can create a new database table where you keep a record of all successfully emailed users. Then from the plugin, query that table for the user's id, if the row exists you never email again, if the email delivery fails don't add them to the list.

1
  • onUserAfterLogin is definetly the best way. OP should also go for option 1.. There is no need for a database table. I have this working without problems. A failure of the email sending will normaly not be detected by Joomla anyway, once it is set up correctly. So there needs to be only a notification to an admin if the whole setup is wrong..
    – Javatasse
    Oct 7, 2018 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.