Send email to site admin when a person clicks a button/link

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
zzz412
I've been banned!
Posts: 10
Joined: Wed Feb 21, 2024 5:03 pm

Send email to site admin when a person clicks a button/link

Post by zzz412 » Sun Feb 25, 2024 9:41 pm

I would like to send an email to the site admin when someone clicks a button/link in a Joomla module. The email will say something like "Someone clicked this button".

I do not want the email address or any secure information (e.g. SMTP username/password) visible to anyone on the frontend.

Is this possible to do with PHP or Javascript?

User avatar
pablop76
Joomla! Intern
Joomla! Intern
Posts: 75
Joined: Sat Dec 25, 2021 10:03 am
Location: Polska
Contact:

Re: Send email to site admin when a person clicks a button/link

Post by pablop76 » Mon Feb 26, 2024 8:26 am

Maybe use it google tag menager?
Paweł
Company website: https://web-service.com.pl/
- Joomla passionate, Polska, Skierniewice

User avatar
Pavel-ww
Joomla! Ace
Joomla! Ace
Posts: 1612
Joined: Tue Jun 30, 2020 12:17 pm

Re: Send email to site admin when a person clicks a button/link

Post by Pavel-ww » Tue Feb 27, 2024 7:15 am

Hi. Purely theoretically, I did not check. You can publish a hidden form and translate the click from your button to form's submit button through JS. I think this should work. But keep in mind, you need to protect this form from spam, that will make it difficult to obtain notifications. Therefore, the best option is to use Google Analytics with configured goal and track events in its interface.

robbiej
Joomla! Apprentice
Joomla! Apprentice
Posts: 43
Joined: Wed Apr 06, 2016 11:22 am

Re: Send email to site admin when a person clicks a button/link

Post by robbiej » Fri Mar 08, 2024 8:37 am

You could write a bit of javascript that ran when the button was clicked, and then sent an ajax request to the server. You should be able to use com_ajax - see https://docs.joomla.org/Using_Joomla_Ajax_Interface - to run a function in your module.

Inside your module function you can use the Joomla mail functions to send the email - see eg https://docs.joomla.org/Sending_email_from_extensions

zzz412
I've been banned!
Posts: 10
Joined: Wed Feb 21, 2024 5:03 pm

Re: Send email to site admin when a person clicks a button/link

Post by zzz412 » Fri Mar 08, 2024 7:39 pm

Thanks. It's a start.

Those docs were written for Joomla v2.5 (and most of the links are broken); some methods may still exist in Joomla 4.4 (viewtopic.php?t=994165).

What I need is to run some PHP-written code when a button is clicked but I don't know how to do that and I do not want to install an extension just to run PHP.

User avatar
ceford
Joomla! Hero
Joomla! Hero
Posts: 2653
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: Send email to site admin when a person clicks a button/link

Post by ceford » Sat Mar 09, 2024 11:58 am

You will need a custom module! You will need to use JavaScript to send an asynchronous message to the server. You will need some server side code to respond to the message - it may send an email but it could do something else. For example, it could send you individual notices or a summary once an hour or once a day. You may need to prevent multiple button presses. You will likely need a database table to keep track of all these interactions.

Interesting small project! There are documentation snippets in different places that could be put together for someone wanting to take it on. For example this one shows an example of a button click that changes a database table and returns updated button text (in an administrator component):

https://docs.joomla.org/J4.x:Joomla_4_T ... le_Toggles

zzz412
I've been banned!
Posts: 10
Joined: Wed Feb 21, 2024 5:03 pm

Re: Send email to site admin when a person clicks a button/link

Post by zzz412 » Sat Mar 09, 2024 9:11 pm

I do not want a button to toggle tables.

I want:

1_ Click a button in a module, e.g. a Submit button in a form
2_ This action will trigger a PHP function to send an email

I do not know how to trigger a PHP function to send an email.

I do not think I want Javascript. JS will expose the address used in sending the email.


Post Reply

Return to “Joomla! 4.x Coding”