-1

How do i get the value from the select in to my mail?


php code

if (isset($_POST['voorletters']) && isset($_POST['achternaam']) && isset($_POST['geboortedatum'])
        && isset($_POST['email'])){
        $voorletters = $_POST['voorletters'];
        $achternaam = $_POST['achternaam'];
        $geboortedatum = $_POST['geboortedatum'];
        $email = $_POST['email'];
        $selectedOption = $_POST['pakketkeuze'];

        if (!empty($voorletters) && !empty($achternaam) && !empty($geboortedatum) && !empty($email)){

            $selectedPakketkeuze  = 'None';
            if(isset($_POST['pakketkeuze']) && is_array($_POST['pakketkeuze']) && count($_POST['pakketkeuze']) > 0){
                $selectedPakketkeuze = implode(', ', $_POST['pakketkeuze']);
            }

            $to = 'contact@pkschoonmaakdiensten.nl'; // Waar moet het naartoe?
            $sebject = 'Inschrijfing'; // Het onderwerp van het bericht

            $body = 'this is a test'."\n\n".'Voorletters: '.$voorletters."\n".'Achternaam: '.$achternaam."\n".'Pakketkeuze: '.$Pakketkeuze;

            $headers = 'From: '.$email;

            if (@mail($to, $sebject, $body, $headers)){
                echo 'the email send';
            }else{
                echo 'error sending email';
            }

        }else{
            echo 'er is iets niet ingevuld'; 
        }       
    }           

html code

I need this value from this option, so when selected it will turn up in the mail when it will be sended.

<tr>
<td class="form-label"><h2>Abonnement keuze *</h2></td> 
<td>
    <span>
        <select name="pakketkeuze" class="selection-menu-inschrijfform">
            <option> --- </option>
            <option value="basic"> Basic</option>
            <option value="normaal"> Normaal</option>
            <option value="plus"> Plus</option>
        </select>
    </span>
</td>

Any help is welcome

user3638080
  • 37
  • 1
  • 6

3 Answers3

0

You can just do this:

$pakketKeuze = $_POST['pakketkeuze'];

If basic was selected wen the form was submitted, $pakketKeuze will contain the string 'basic'

Jonan
  • 2,485
  • 3
  • 24
  • 42
0

You have used an undefined variable : $Pakketkeuze in email body variable. Instead, you may want to try the below code to get selected value of drop down box.

$body = 'this is a test'."\n\n".'Voorletters: '.$voorletters."\n".'Achternaam: '.$achternaam."\n".'Pakketkeuze: '.$_POST['pakketkeuze'];
0

Change this line:

$body = 'this is a test'."\n\n".'Voorletters: '.$voorletters."\n".'Achternaam: '.$achternaam."\n".'Pakketkeuze: '.$Pakketkeuze;

to this:

$body = 'this is a test'."\n\n".'Voorletters: '.$voorletters."\n".'Achternaam: '.$achternaam."\n".'Pakketkeuze: '.$selectedOption;

Also, you can delete the following:

$selectedPakketkeuze  = 'None';
if(isset($_POST['pakketkeuze']) && is_array($_POST['pakketkeuze']) && count($_POST['pakketkeuze']) > 0){
    $selectedPakketkeuze = implode(', ', $_POST['pakketkeuze']);
}

As $_POST['pakketkeuze'] will not be an array unless you have multiple dropdowns called pakketkeuze in which case you need to add this inside your if to go with the change made before:

if(isset($_POST['pakketkeuze']) && is_array($_POST['pakketkeuze']) && count($_POST['pakketkeuze']) > 0){
    $selectedPakketkeuze = implode(', ', $_POST['pakketkeuze']);
    $selectedOption = $selectedPakketkeuze;
}
Pete
  • 57,112
  • 28
  • 117
  • 166
  • can u also tel me how to get a value out a few checkboxes with an array[] `

    Woensdag

    `
    – user3638080 Jul 14 '14 at 10:58
  • [Have a look at this post](http://stackoverflow.com/questions/4997252/get-post-from-multiple-checkboxes), it should help – Pete Jul 14 '14 at 11:01