简体   繁体   中英

php send variables to another file without form

I've looked at so many stack overflow questions to find my solution, but none of the questions I try are what I am looking for (so if you know of one that fits my question, please tell me). What I have is a php page that processes a form. It looks like this:

<?php
$var1 = htmlentities($_POST['var1']);
$var2 = htmlentities($_POST['var2']);

$conn = mysqli_connect('localhost','user','pass','db');
$query = "INSERT INTO table (var1,var2) VALUES ('$var2','$var2)";
$doQuery = mysqli_query($conn,$query);

if($doQuery) {
    // this is where script should go (i think) to send the variables to the email page
header("Location: /path/to/next/page"); // this just sends the user to the next page. NOT PART OF EMAIL PAGE
}

else {
header("Location: /path/to/back/page");
}

mysqli_close($conn);
?>

so its a basic form handler that sends you to the next page if all goes well.

I have another page that is sends an email notification to someone when they successfully go through the first page. It also processes all of the other email notification worthy forms as well. that's the reason I can't just take the script and put it into the top page.

So, what I am trying to do is figure out a way to send the $var1 and $var2 to the email file without completely redirecting the user. I don't need a response back from the email file.

I hope that made sense.

thanks in advance

Quite simple, really:

// your code above
require 'send-email.php';

And your send-email.php would reference $var1 and $var2 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM