From 8592bc0c3c65e3cf916acfd03e6078819106f99d Mon Sep 17 00:00:00 2001 From: Mark Wane Date: Sun, 6 Oct 2019 10:03:07 +0100 Subject: [PATCH] Email result link to user --- ajax.php | 5 +++++ classes/user.class.php | 14 ++++++++++++++ result.php | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ajax.php b/ajax.php index 9b7ef39..79ed43d 100644 --- a/ajax.php +++ b/ajax.php @@ -1,4 +1,5 @@ $index_int ){ $data_arr['ans'][] = array( 'id' => $answer->getID(), 'text' => $answer->getText() ); } } else { + $user = new User( $_POST['user'] ); + $accessKey_str = $quiz->saveResult( $_POST['user'] ); + $user->emailResult( $accessKey_str ); + $data_arr = array( 'done' => true, 'result' => $accessKey_str diff --git a/classes/user.class.php b/classes/user.class.php index 7d7e387..28fcd6a 100644 --- a/classes/user.class.php +++ b/classes/user.class.php @@ -105,4 +105,18 @@ class User extends Item { public function getEmail(){ return $this->email_str; } + + /** + * Email a link to the results page + * + * @param string $accessKey_str Access key for result + */ + public function emailResult( string $accessKey_str ){ + $to_str = $this->name_str . " <" . $this->email_str . ">"; + $subject_str = "Your results"; + $url_str = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['SERVER_NAME'] . dirname( $_SERVER['PHP_SELF'] ) . "/result.php?key=" . $accessKey_str; + $body_str = "Thank you for completing the quiz, your result can be viewed at the following link. \r\n" . $url_str; + + mail( $to_str, $subject_str, $body_str ); + } } diff --git a/result.php b/result.php index b855cd5..0d12d21 100644 --- a/result.php +++ b/result.php @@ -52,7 +52,7 @@ if ( $scorePer_num > $averagePer_num + 10 ){

Average score

-
+