How to display success message correctly and delete it when the page is refreshed

You’re looking for Flash Messages. Flash Messages are messages stored in session and deleted right after they are retrieved. You can find some implementation on github: https://github.com/plasticbrain/PhpFlashMessages

<?php 

// Start a Session
// Read about managing session with WordPress

// Instantiate the class
$fm = new \Plasticbrain\FlashMessages\FlashMessages();

// Process form e.g. send an email and add success message
$msg->success('Thank you for sending message!');

// Display message
if( $fm->hasMessages('success') ) {

    /**
     * This line will display success message and also remove it
     * from session. After refresh $fm->hasMessages('success')
     * will return false
     */ 
    $fm->display('success'); 
}