I need to create a module with just one button (like Join Us). When a user click on this button, an email will be sent to the user and to administrator. In this email must be written the username who click the button.

So i need to create a task to get username and send this username to the administrator. Any idea to solve this question?


  • 3
    So we know what you're trying to achieve and it's very do-able. What have you tried so far? Please show some efforts as we're not here to write all your code for you
    – Lodder
    Feb 23, 2016 at 13:53
  • 1
    If you are not familiar with creating a module from scratch I would recommend installing Flexi Custom Code Module and just creating a simple form using PHP that does what you are looking to do. Getting the users email and username can be done easily as well. $user = JFactory::getUser();
    – Terry Carter
    Feb 23, 2016 at 18:10

1 Answer 1


Download Flexi Custom Code Module from the JED. Install the module and publish it to the position of your choice. Below the custom code box leave the option to use PHP on and disable the cleanup of html, js, and css. Enter this code into the custom code box:


$JInput = JFactory::getApplication()->input;
$sendMail = $JInput->get('sendMail', '', 'string');
$userName = $JInput->get('username', '', 'string');
$userEmail = $JInput->get('email', '', 'string');
$user = JFactory::getUser();

if(isset($sendMail) && $sendMail == 'sendNow'){

    JFactory::getApplication()->enqueueMessage('Contact request successfully submitted.', 'message' );

    $html = "";
    $html .= "<h2>New Contact Request Received</h2>";
    $html .= "<p>A new contact request has been sent by " . $userName . ". The user's email address is: ".$userEmail.".</p>";

    $subject = "Contact Request";
    $from = array("[email protected]", "Website Contact");

    $mailer = JFactory::getMailer();
    $mailer->addRecipient("YOUR EMAIL ADDRESS");

    $submitted = "";
    $submitted .= "Your contact request has been successfully received. Someone will contact you soon.";
    echo $submitted;

<form action="<?php echo JUri::current();?>" method="post" name="adminForm" id="adminForm" class="form-validate">
<input type="hidden" name="sendMail" value="sendNow" />
<input type="hidden" name="username" value="<?php echo $user->username;?>" />
<input type="hidden" name="userEmail" value="<?php echo $user->email;?>" />
<input type="submit" value="Request Contact" />
<?php } ?>

Replace the email appropriate code to match your domain and email address settings.

I haven't tested this but it should work for what you are looking for.

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.