manuelBetancurt
manuelBetancurt

Reputation: 16128

php jquery send post parameters to other php page

Im new to web technology, and im having a few roadblocks,

I have a php page that sends post mail request in a JS by calling another php page,

but I need to pass to that new php page the values for my mail, all works fine with hardcoded vals, but I need to know how to pass the parameters to my php send mail page,

here the code for the main php page:

<script>
...
$.post( "send-mail-parklane-suscrib.php" , { name: "John", time: "2pm" });
...
</script>

and here the code for the send-mail-parklane-suscrib.php

<html>
<head><title>PHP Mail Sender</title></head>
<body>
<?php
session_start(); 
echo("chamb");
$to = '[email protected]';
$from = '[email protected]';
$subject = 'Parklane Financial Subscribe';
$headers = 'From: [email protected]' . "\r\n".
'Reply-To: [email protected]'. "\r\n".
'Return-Path: [email protected]' . "\r\n".
'X-Mailer: PHP/' . phpversion();
$message = "SS9 tkt ss9!!!";
mail($to, $subject, $message, $headers, "-f $from");
?>
</body>
</html>

so how to access this vals on my send mail page?

thanks!

Upvotes: 0

Views: 337

Answers (2)

MackieeE
MackieeE

Reputation: 11862

They'll be saved into a superglobal, $_POST.

<?php
   echo $_POST["name"]; //Echos John
   echo $_POST["time"]; //Echo 2pm

   /**
    *  You may see at anytime if your page has
    *  any set by: (Dev use only) Printing the contents
    *  of the $_POST Array.
   **/
   print_r( $_POST );

   /**
    * Note, it's important you check the existence 
    * & verify any values sent.
   **/
  if ( isset( $_POST["name"] ) && $_POST["name"] !== '' ) {
    //Code
    $Name = $_POST["name"];
  }
?>

There are others too:

  • $_GET - For GET Requests
  • $_POST - For POST Requests
  • $_COOKIE - For Cookies
  • $_REQUEST - For All of the Above.

Upvotes: 1

chiliNUT
chiliNUT

Reputation: 19573

Use $_POST

$name=$_POST['name'] //John 

etc.,

Upvotes: 0

Related Questions