php 将变量发送到另一个没有形式的文件

php send variables to another file without form

我已经查看了很多堆栈溢出问题来找到我的解决方案,但是 none 我尝试的问题正是我要找的(所以如果你知道一个适合我的问题,请告诉我)。我拥有的是处理表单的 php 页面。它看起来像这样:

<?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);
?>

所以它是一个基本的表单处理程序,如果一切顺利,它会将您带到下一页。

我有另一个页面,当他们成功浏览第一页时,会向他们发送电子邮件通知。它还处理所有其他电子邮件通知形式。这就是为什么我不能直接把剧本放到首页的原因。

所以,我想做的是想出一种方法将 $var1$var2 发送到电子邮件文件,而无需完全重定向用户。我不需要电子邮件文件的回复。

我希望这是有道理的。

提前致谢

很简单,真的:

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

而您的 send-email.php 将引用 $var1$var2