0

My form currently collects data entered by the user, and then presents it in a particular format on a new page.I would like this data that is presented on my new page to be sent automatically via email to the admin aswell.

I've looked around for the Mail function in PHP but I cannot seem to send form data collected from a dropdown menu and neither can I control how the output is being sent via email.

<form action="dealform.php" method="post">

    <div class="form-row">
        <div class="col">

            <label for="amount">Currency</label>
            <select class="form-control" name="currency" id="exampleFormControlSelect1">
                <option disabled selected value> -- select a Currency -- </option>
                <option value="€">EUR</option>
                <option value="$">USD</option>
                <option value="A$">AUD</option>
                <option value="£">GBP</option>
                <option value="₽">Rouble</option>
                <option value="R">Rand</option>
                <option value="¥">Yen</option>
            </select>
        </div>
        <div class="col">

            <label for="amount">Amount</label>
            <input type="text" class="form-control" name="amount" id="amount" >
        </div>
    </div>
    <br>
    <button type="submit" class="btn btn-primary">Submit</button>
    <button type="reset" class="btn btn-primary">Reset</button>

</form>

And this is the dealform.php:

<p>
Amount: <?= $_POST["currency"] ?> <?= $_POST["amount"] ?>
</p>

At the moment when I click submit the selected currency and amount show up neatly like the following example: Amount: $100.

I cannot seem to send this information automatically to an email of my choice in this format, am I missing something?

Massive
  • 5
  • 3
  • I am asking how to implement the mail() function to send the information I am collecting to an admin email address automatically when clicking the submit form. AND for it to be sent in a format/layout of my choosing. The code I've pasted is the code I have – Massive Feb 14 '19 at 20:44
  • 2
    Start perhaps with the `mail` function. You can find that at http://php.net/manual/en/function.mail.php. But you may want something more along the lines of this answer: https://stackoverflow.com/a/14456761/282194 – ThatBlairGuy Feb 14 '19 at 22:02

1 Answers1

0

You are missing "echo" to put that value after "Amount:"

    <p>
    Currency: <? echo $_POST["currency"]; ?> Amount: <? echo $_POST["amount"]; ?>
    </p>

should make it generate proper text to mail.
To send message with these values, dealform.php will contain

$message="<p> Currency:". $_POST["currency"]. " Amount:". $_POST["amount"]; 
mail('caffeinated@example.com', 'My Subject', $message);
  • http://php.net/manual/en/function.echo.php - the OP is NOT missing "echo"....... - and stated that when submit was clicked the data showed...... I won't downvote this, though you should be careful making statements like "You are missing..." without double checking the manual! Many on SO will downvote such things! – Apps-n-Add-Ons Feb 15 '19 at 12:57
  • @CFPSupport Will go through the link you posted. Thanks. –  Feb 16 '19 at 07:19