-1

So I've made a form validation in Javascript. It validates wether the input from the form is correct. So when all of the input fields are correctly filled in, I want to send an e-mail to the user containing some information:

var to = "info@test.com";
var subject = "subject";
var message = "This is the message";

So I want to change these variables into PHP variables so I can do the following in PHP:

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

So is it possible to change these Javascript variables into PHP variables? Or is there a better way to send the email using Javascritp? Thanks in advance!

Martijn
  • 514
  • 6
  • 12
  • 2
    There's just too much wrong with this question to start answering. You should start reading up on the very basic principles of clientside and serverside processing first. – Niels Keurentjes Oct 06 '14 at 20:39
  • Javascript works on the client, while php is executed serverside. Read up about this some more and it shall be unveiled to you by itself. – malifa Oct 06 '14 at 20:40

1 Answers1

4

So is it possible to change these Javascript variables into PHP variables?

You can't use JavaScript to change anything in PHP because PHP shuts down once it renders the page.

You can post JavaScript variables to a new page, either by redirecting, submitting a form, or making an AJAX call, etc... but you always need to make that additional server call.

Or is there a better way to send the email using Javascritp?

You can't send emails using only JavaScript.

Shomz
  • 37,421
  • 4
  • 57
  • 85