0

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?

Thanks!

  • 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 '16 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 '16 at 18:10
2

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:

<?php
JHtml::_('behavior.formvalidation');

$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' );

    //GENERATE DATA TO EMAIL TO ADMINS  
    $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("noreply@yourwebsite.com", "Website Contact");

    //SEND THE EMAIL
    $mailer = JFactory::getMailer();
    $mailer->setSender($from);
    $mailer->addRecipient("YOUR EMAIL ADDRESS");
    $mailer->setSubject($subject);
    $mailer->setBody($html);
    $mailer->isHTML();
    $mailer->send();

    //GENERATE DATA TO DISPLAY TO THE USER
    $submitted = "";
    $submitted .= "Your contact request has been successfully received. Someone will contact you soon.";
    echo $submitted;

}else{?>
<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" />
</form>
<?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, privacy policy and cookie policy

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