mardi 28 janvier 2020

I want to send an E-Mail inside JavaScript code using PHP [duplicate]

Is it possible that I can send an email by picking an item from the dropdown list. By picking the option BEHOBEN the mail should be sent.

My try:

function myFunction() {
        var selectNEW = document.getElementById('select'); //dropdownlist id
        var selectedText = selectNEW.options[selectNEW.selectedIndex].text; //get text from list
        if (selectedText == "BEHOBEN") {
            alert("Successfully");
            <?php

            $to = "/*to mail*/";
            $subject = "Success";
            $message = 'Everything successfully finished';
            $header = 'From: /*my mail*/';

            mail($to,$subject,$message,$header);

            ?>
        } else {
            alert("You have to pick an option from the DropDownList");
        }
    }

The button

<div class="sendButton">
        <input class="send" onclick="myFunction()" type="submit" name="send" value="Success"></input>
    </div> 

But in my case the email would not be sent.




Aucun commentaire:

Enregistrer un commentaire