http - First time clicking hyperlink (when it is blue) in word 2007 results in incorect response on my website php

one text

So I have to open my website from a hyperlink in my testdocumentation. I have to do it this way to ensure my test is easy to use. Sadly I seem to be getting very weird behavior from my webpage.

So when you open the link it is supposed to send an email and then respond with a success message and delete all records from the database. This works if you just enter the link in the browser and when you open the hyperlink for a second time.

But when you open the link for the first time (and you do have something in the database) it sends the email but instead of giving a response with success like it should, it instead seems to go trough my else statement after going trough my if statement and it gives response that there are no emails in the database.

so first time clicking the link from word 2007(also from PowerPoint) it does the following

  1. sends the mail which is what happens if the if statement is met
  2. respond that there are no records in the database which happens if the else statement is met

this is my routing

<!DOCTYPE html>
<html lang="nl">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="stylesheets/style.css">
    <title>Ninebits Enquete</title>
</head>
<?php



//Models
require_once    '../Models/Model.php';
require_once    '../Models/Database.php';
require_once    '../Models/Question.php';
require_once    '../Models/Survey.php';
require_once    '../Models/Mail_Info.php';
require_once    '../Models/Mail.php';
require_once    '../Models/Answer.php';

//controllers
require_once    '../Controllers/surveyController.php';
require_once    '../Controllers/mail_infoController.php';
require_once    '../Controllers/mailController.php';
require_once    '../Controllers/answerController.php';


//views
require_once    'views/surveyView.php';
require_once    'views/finishView.php';
require_once    'views/selectionView.php';
require_once    'views/dashboardView.php';
require_once    'views/previouslySavedView.php';
require_once    'views/errorView.php';




//will get the URL so it can be used for routing
$url = isset($_SERVER['PATH_INFO']) ? explode('/', ltrim($_SERVER['PATH_INFO'],'/')) : '/'  ;

//this is where my problem comes from by calling this
if($url == '/' && $_SERVER["REQUEST_METHOD"] === "GET")
{
        $mc = new mailController;

        $mc->sendMail();
}


else
{
    if($url[1] == 'list')
    {

        $sc = new surveyController();
        $mic = new mail_infoController();


       $list = $mic->checkadress($_GET['type']);
       $sc->displayPage($list);

    }



    else if($url[1] == 'finish')
    {
        $ac = new answerController();

        $ac->showFinish();
    }

    else if($url[1] == 'selection')
    {
        $sc = new surveyController();

        $sc->selectionScreen();
    }

    else if($url[1] == 'dashboard')
    {

      $ac = new answerController();
      $ac->getCalculatedValue($_GET['id']);


    }

    else
    {
        header('HTTP/1.1 404 Not Found');
        die("<h1>404</h1> pagina $url[1] kunnen wij niet vinden of bestaat niet. ");
    }


}

?>
</html>

my function that is called when calling the link

    /**
     *
     *
     * sends the email with link to the client.
     */
    public function sendMail()
    {

        $mail = new Mail();

      //it goes through here when calling the link the first time from word
        if(!$mail->exception)
        {
            $info = $mail->mails;

            foreach ($info as $infoItem)
            {
                $adress = $infoItem["mailadress"];

                if(filter_var($adress, FILTER_VALIDATE_EMAIL) )
                {
                    $hash = $this->createLink($infoItem['client'], $infoItem['survey']);
                    $mail->mail_info->addMailInfo($infoItem['client'], $hash);

                    $to = $infoItem["mailadress"];
                    $subject = "Enquete";
                    $message = "<html><body>";
                    $message .= "<h1>Geachte ".$infoItem['client'];
                    $message .= "</h1>";
                    $message .= "<h3>Bedankt voor het gebruiken van onze service en producten</h3>";
                    $message .= "<p>Om ons te laten weten wat u van de service en producten vondt willen wij u graag vragen om de enquete in de link hieronder in te vullen</p>";
                    $message .= "<a href='https://ontwikkeling.ninebits.nl/lab/stage/danny/Enquete/public/list?type=$hash'>Ninebits Enquete</a>";
                    $message .= "<br>";
                    $message .= "<br>";
                    $message .= "<p>met vriendelijke groet,</p>";
                    $message .= "<p>Het hele Ninebits team</p>";
                    $message .= "</body></html>";



                    $headers = "from: Ninebits\r\n";
                    $headers .= "MIME-Version: 1.0\r\n";
                    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

                    mail($to, $subject, $message, $headers);


                    $mail->deleteMails($infoItem['id']);

                      //this is the response I am expecting everything up to here seems to work
                        echo 'success <br>';

                }

                else
                {
                   //it does not seem to go in this else here which is good in this case

                    echo 'Dit is geen correct email adres<br>';

                    $mail->deleteMails($infoItem['id']);

                    if($mail->exception)
                    {
                       echo $mail->exceptionMessage;
                    }
                }
            }

        }

         //but then it responds with this else here
         else
         {
             echo $mail->exceptionMessage;
         }
    }
}

The browser console and all the log data I was able to get points to only 1 get call being performed

Source