Home » Php » javascript – How to generate a random number and export it to an automated email?

javascript – How to generate a random number and export it to an automated email?

Posted by: admin February 25, 2020 Leave a comment

Questions:

I’m using jqueryform.com form builder to create a registration form. I’d like the registration form to assign each registrant user with an account number (randomly generated 6-digit number) and then I’d like the program to place the account number in an automated email that is already programmed to send out when the form is submitted.

The form files are .js and .php files. I believe the automated email program pulls variables out of .php script such as the variables {AutoID} or {Date}, for example:

Automated Email Program GUI

I’ve drafted up this random number generator:

  <p>
    <?php
    $randomNumber = rand(100000,999999);
    print_r($randomNumber);
    print_r("\n");
    ?>
  </p>

Where would I put this and how can I reference its product in the automated email program GUI?

How to&Answers:

Instead of the automated email program you can use PHP to send emails like below

<?php

$randomNumber = rand(100000,999999);
$to_email = '[email protected]';
$subject = 'You account info';
$message = 'Your account number is '.$randomNumber;
$headers = 'From: [email protected]';
mail($to_email,$subject,$message,$headers);

?>

But if you must use the program then you need to add a hidden input to your form and pass the random number as a value like this

<input type="hidden" name="randomValue" value="<?php echo $randomNumber;?>">

then retrieve the value from the form as {randomValue}