-2

I wanna make a form where the variables are gotten by the URL My_url com/email.html?name=Myname

For example the name is introduced by default as "MyName" IMAGE

How would could I do this? The HTML code. https://codepaste.net/sqq43i

The PHP code.

$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_message = $_POST['text'];

$mail_to = 'MyMail';
$subject = 'Message from a site visitor '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);
Phil
  • 3
  • 2

2 Answers2

-1

just replace every place which is written POST with GET (both client and server)

like so:

$field_name = $_GET['name'];
$field_email = $_GET['email'];
$field_message = $_GET['text'];

and

<form class="form" action="form_handler.php" method="GET" id="form1">
Nir O.
  • 1,563
  • 1
  • 17
  • 26
-1

Don't use POST in that case, Instead use GET.

for ex:

$field_name = $_GET['name'];
$field_email = $_GET['email'];
$field_message = $_GET['text']; => the key here must be identical to the one in the url

the rest of your code should be the same assuming there is no syntax errors

Faical ARAB
  • 387
  • 3
  • 14
  • I replaced all the POST for GET, still not working – Phil Mar 04 '17 at 20:32
  • PLs can you erase anything below this 3 lines of code and try to echo the $field_name like : echo $field_name and see if it prints the value you entred in the name input. if this worked than you have another problem – Faical ARAB Mar 04 '17 at 20:40
  • The 3 variable from the Form are shown in the next page, but I wanna have them in the Form before – Phil Mar 04 '17 at 21:34
  • Working now, just changed the ending from ".html" to ".php" and used this as input `code` `code` – Phil Mar 04 '17 at 22:09
  • I'm glad this helped – Faical ARAB Mar 04 '17 at 22:34