gpt4 book ai didi

php - 带有 PHP 确认邮件的预订系统

转载 作者:行者123 更新时间:2023-11-27 23:38:42 26 4
gpt4 key购买 nike

如标题所示,我正在用 HTML/PHP 制作预订系统。首先需要填写一个 (HTML) 表单,并将这些值传递给 reservation-send.php 文件。该 .php 文件生成一封电子邮件,其中包含来自表单的几个值和一个确认链接(包括哈希码),该链接将发送给将要确认的人。当按下链接时,它将触发另一个 .php 文件,bevestiging.php。该文件检查哈希码和电子邮件,如果正确,则发送另一封电子邮件,确认已进行。

但总是出现“错误!”。我认为我的 url 确认链接的输出是问题所在。(见图)

PHP - reservation-send.php

<?php
require_once 'inc/securimage/securimage.php';

/////////////////////////////////////
// Change this email address ////////
$email = "test@test.be"; //make this test@test.be on purpose ;)

/////////////////////////////////////

$required = array('day', 'month', 'year', 'hour', 'minutes', 'ampm', 'name', 'email', 'captcha', 'phone', 'amount');
$response = array('status' => 'failed', 'errors'=>array());

if(isset($_POST['reservation'])) {
foreach($_POST['reservation'] as $field => $value) {
//check required field if empty
if($value == '' && in_array($field, $required)) {
$response['errors'][$field] = $field;
}
}

//validate email
if(!isset($response['errors']['email'])) {
if(!filter_var($_POST['reservation']['email'], FILTER_VALIDATE_EMAIL)) {
$response['errors']['email'] = 'email';
}
}

//validate captcha
if(!isset($response['errors']['captcha'])) {
$securimage = new Securimage();
if ($securimage->check($_POST['reservation']['captcha']) == false) {
$response['errors']['captcha'] = 'captcha';
}
}

}

if(empty($response['errors'])) {
$response['status'] = 'success';

$data = $_POST['reservation'];

//Generate email link

//save mail of who made the reservation - get from form
$email_reservering =$data['email'];

//generate hash code
$hash = md5($email_reservering);

//generate link with hash code
$link = "http://lanes.be/baronie/bevestiging.php?email=”.urlencode($email_reservering).”&hash=$hash";

$headers = "";
$message .= "Dag Lode en Eva, via de website kregen jullie een nieuwe reservatie, gelieve de persoon zo snel mogelijk een bevestigingsmail te sturen!";
$message .= "\n\n";
$message = $data['message'];
$message .= "\n\n";

$message .= " Telefoon: " . $data['phone'];
$message .= "\n\n";
$message .= " Lunch/Diner: " . $data['booking-type'];
$message .= "\n\n";
$message .= " Aantal personen: " . $data['amount'];
$message .= "\n\n";
$message .= " Email: " . $data['email'];

$message .= "\n\n";
$message .= " Datum: " . $data['day'];
$message .= "\n\n";
$message .= " Maand: " . $data['month'];
$message .= " " . $data['year'];
$message .= "\n\n";
$message .= " Tijdstip: " . $data['hour'] . " " . $data['minutes'] . " " . $data['ampm'];
$message .= "\n\n\n\n";
$message .= "<a href='".$link."'>Bevestig</a>";

$subject = 'Nieuwe reservatie via de website';
$headers = 'From: '. $data['email']. "\r\n" .'Reply-To: '. $data['email']. "\r\n" .'X-Mailer: PHP/' . phpversion();

if (mail($email, $subject, $message, $headers)) {

} else {
$response['status'] = 'failed';
}
}

echo json_encode($response);

PHP - bevestiging.php

<?php

//retrieve email and hash code from link
$email_reservering = urldecode($_GET['email_reservering']);
$hash = $_GET['hash'];

//check if hash code matches

if (md5($email_reservering) == $hash)
{
//succes
$headers = "";
$message .= "reservering bevestigd!";
$message .= "\n\n";

$subject = 'Bevestiging reservering';

if (mail($email, $subject, $message, $headers)) {

} else {
$response['status'] = 'failed';
}
}
else
{
//error
echo "error!";
}

?>

输出 enter image description here

错误原因(我认为)

$link = "http://lanes.be/baronie/bevestiging.php?email=”.urlencode($email_reservering).”&hash=$hash";

$message .= "<a href='".$link."'>Bevestig</a>";

最佳答案

$link 的构建方式有误。看看我替换的引号。将其更改为:

$link = "http://lanes.be/baronie/bevestiging.php?email=".urlencode($email_reservering)."&hash=".$hash;

此外,您不需要 urldecode $_GET变量

关于php - 带有 PHP 确认邮件的预订系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32650357/

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