Send data from form to email

I have problem with send data from page. Web page is responsible and form is ok when fill on the mobile.
When fill form in computer (i have 2 layers, 1-320 px to 1100px width and 2-over 1100px) data form is empty.

function:
	 hypeDocument.getElementById('resultBox').innerHTML = "";	
var name = hypeDocument.getElementById('name').value;
var email = hypeDocument.getElementById('email').value;
var phone = hypeDocument.getElementById('phone').value;
var message = hypeDocument.getElementById('message').value;
	 
	
	

var obj = new Object();
var PostName = name;
var PostemailAddr =email;
var Postphone = phone;
var Postmessage = message;
 
	
phpEmailer(PostName, PostemailAddr,Postphone,Postmessage);
	
function phpEmailer(PostName, PostemailAddr,Postphone,Postmessage){

$.post("./email2.php", { name: PostName, email: PostemailAddr,phone: Postphone,message: Postmessage} )

 .done(function() {
 
 hypeDocument.getElementById('resultBox').innerHTML = "Odoslané!" ;
     
})

.fail(function() {
//do anything on failure ...
 hypeDocument.getElementById('resultBox').innerHTML = "Neodoslané!";
 
});
}

PHP file:

<?php
    // define variables and set to empty values
    
    if ($_SERVER["REQUEST_METHOD"] == "POST") {

        $email = $_POST["email"];
        $name = $_POST["name"];
        $phone = $_POST["phone"];

        $message = $_POST["message"];

    }

    $subject = "Dotaz z web stránky";
    $headers = "From: $email\n";
    $to = "info@trixs.sk";
    $body = "Zákaznik odoslal mail z vášho webu.\n

  Email : $email\n
Meno: $name\n
Telefón:$phone\n
Správa: $message
    ";

    mail($to,$subject,$body,$headers);

    #send confirmation email to users email address
    $user = "$email";
    $usersubject = "Ďakujem";
    $userheaders = "From: info@trixs.sk\n";
    $usermessage = "Ďakujem za návštevu našej stránky.";


    mail($user,$usersubject,$usermessage,$userheaders);
    echo "$user";
    ?>

Thanks!

if the form is not part of a persistent symbol the elements will be duplicated for each layout.
so an approach using id’s to grap the elements data will not work.

so:
use a persistent symbol
or
work with class instead (the extensionthread includs a nice method to get the current layout/scene to query … )

1 Like

Thank you very much. It’s working now!