gpt4 book ai didi

php - 多页php表单后的电子邮件mysql查询

转载 作者:太空宇宙 更新时间:2023-11-03 12:04:00 24 4
gpt4 key购买 nike

我已成功创建一个多页 php 表单,将所有数据上传到 mysql 数据库。现在我正在尝试让这个邮件功能与之一起工作,这样我们就可以在每次有人成功填写表格时收到一封电子邮件。我现在收到电子邮件,但没有收到表格中的信息。我不确定我做错了什么,我猜这与 SESSION 有关,但我很难找到解决方案。

这是我正在使用的代码:

<?php
session_start();

foreach ($_POST as $key => $value) {
$_SESSION['post'][$key] = $value;
}

extract($_SESSION['post']); // Function to extract array
$connection = mysql_connect("mysql.database.com", "r-----a", "An-----1!");
$db = mysql_select_db("---------", $connection); // Storing values in database.
$query = mysql_query("insert into detail (whenadded,yourname,reservationid,reservationname,property,eta,cellphone,email,signature,petcontract) values(Now(),'$yourname','$reservationid','$reservationname','$property','$eta','$cellphone','$email','$signature','$petcontract')", $connection);

/* Set e-mail recipient */
$myemail = "blahblahblah@retreatia.com";

$yourname = ($_POST['yourname']);
$reservationid = ($_POST['reservationid']);
$reservationname = ($_POST['reservationname']);
$property = ($_POST['property']);
$eta = ($_POST['eta']);
$cellphone = ($_POST['cellphone']);
$email = ($_POST['email']);
$petcontract = ($_POST['petcontract']);

/* Let's prepare the message for the e-mail */
$subject = "$yourname has checked in using Express Checkin!";

$message = "

Information of Express Checkin User:

Name: $yourname
Reservation ID: $reservationid
Name on Reservation: $reservationname
Property: $property
Cell Phone: $cellphone
Email: $email
ETA: $eta
Pet Contract: $petcontract

";

/* Send the message using mail() function */
mail($myemail, $subject, $message);

if ($query) {
echo '<div class="absolutecenter boxshadows"><img src="../img/thankyoupage.png" class="img-responsive"></div>';
} else {
echo '<p><span>Form Submission Failed!</span></p>';
}

unset($_SESSION['post']); // Destroying session

?>

该表单还成功地填充了数据库中的所有字段,并从回显中生成了 img 文件...

最佳答案

自从你这样做之后:

extract($_SESSION['post']); // Function to extract array.

...这个 block 是不必要的:

$yourname = ($_POST['yourname']);
$reservationid = ($_POST['reservationid']);
$reservationname = ($_POST['reservationname']);
$property = ($_POST['property']);
$eta = ($_POST['eta']);
$cellphone = ($_POST['cellphone']);
$email = ($_POST['email']);
$petcontract = ($_POST['petcontract']);

事实上,这可能就是您的变量未填充的原因。它们会被空值覆盖,因为 $_POST 不包含之前页面的值。

关于php - 多页php表单后的电子邮件mysql查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27534459/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com