2015-09-18 57 views
2

像標題所示,我正在用HTML/PHP製作預訂系統。首先需要填寫一個(HTML)表單並將這些值傳遞給reservation-send.php文件。 .php文件會生成一封電子郵件,其中包含表單中的一些值和確認鏈接(包括哈希碼),這些鏈接將發送給確認的人員。當鏈接被按下時,它會觸發另一個.php文件,bevestiging.php。該文件檢查哈希碼和電子郵件,如果正確的話發送另一封電子郵件,確認已完成。帶有確認郵件的預訂系統PHP

但總是得到「錯誤!」。我想輸出自己的網址驗證鏈接的問題。(見圖片)

PHP - 預約send.php

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

///////////////////////////////////// 
// Change this email address //////// 
$email = "[email protected]"; //make this [email protected] 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>"; 

回答

2

$鏈接是建立走錯了路。看看我替換的引號。 它改成這樣:

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

而且,你不需要urldecode $_GET變量

+0

改成了你所說的話: Bevestig 現在看起來他的IDD編碼的電子郵件藏漢但仍然得到'錯誤!'點擊它時。 – user3360972

+0

你有任何調試信息?沒有它,很難說什麼是。 順便說一句,如果它自己的錯誤輸出,那麼它因爲 如果(md5($ email_reservering)== $散列)失敗... 它會掉進別處,你回聲錯誤! – RFLdev

+0

我至少將它郵寄給需要確認預訂的人郵寄給同一個emailadress。我需要找到一種方法從表單中檢索電子郵件,並將其保存在bevestiging.php文件中並將其發送到該地址。 – user3360972