0

I'm using Flexi Custom Code to create a button to send an email to me, but it seems to be randomly working. I almost never get the $sendMail parameter. But sometimes it works, and I get the email...

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

$jinput = JFactory::getApplication()->input;
$sendMail = $jinput->get('sendMail', '', 'STRING');

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

    $aId = JRequest::getVar('id');

    $html = "";
    $html .= "<h2>".$aId."</h2>";
    $html .= "<p>test</p>";

    $subject = "Request";
    $from = array("noreply@test.com", "Website Contact");

    $mailer = JFactory::getMailer();
    $mailer->setSender($from);
    $mailer->addRecipient("MY EMAIL");
    $mailer->setSubject($subject);
    $mailer->setBody($html);
    $mailer->isHTML();
    $mailer->send();

    $submitted = "";
    $submitted .= "Request confirmed";
    echo $submitted;

}else{?>

<form action="<?php echo JUri::base() . basename($_SERVER['REQUEST_URI']); ?>" method="POST" name="adminForm" id="sendMailForm" class="form-validate">
<field type="hidden" value="sendNow" name="sendMail" class="required" />
<button type="submit" class="validate">SEND MAIL</button>
</form>

<?php } 
?>

I'm using Joomla 3.8.5

ssten
  • 1,848
  • 1
  • 16
  • 28

2 Answers2

0

lots of strange things, but you can start by replacing 'field' with 'input'. and don't use JRequest, you already have $jinput.

another problem might be that you have a redirect, that changes the post request to a get request. Open (chrome) debugger, and check the network tag (while you are there, check that the sendMail input is indeed there)

JulienV
  • 775
  • 7
  • 12
  • According to [this](https://docs.joomla.org/Client-side_form_validation), 'field' should work fine. JRequest is also not part of the actual problem... And combine `method="POST"` with a GET action also should work according to [this](https://stackoverflow.com/a/4726819/7379503) – ssten Jun 20 '18 at 08:34
  • did you check the requests with the debugger ? I was saying that your post request could be transformed to a get request, depending on what the action url is... – JulienV Jun 20 '18 at 13:54
0

I ended up using CacheControl to disable cache on the page.

And I can get all $_GET parameters from $_SERVER[“REQUEST_URI”]

ssten
  • 1,848
  • 1
  • 16
  • 28