Search code examples
phphtmlfilepageload

PHP page not loading (PHP contact form)


So this is the first time using a php doc. My page worked fine as a .html, in the contact page is a contact form, hence why I have now changed it to a .php file, as the php for the form is at the top of the document. I have yet to send an email successfully. I am not sure if there is an error in the code, do I need to set something up through CPanel?

https://www.decisive-development.com/contact.php - this is the page that is not loading

https://decisive-development.com/ - this is the homepage


<?php
    $message_sent   =   false;
    if(ifsset($_POST['email']) && $_POST['email']  !=  ''){

        if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)  ) {

            $userName   =   $_POST['name'];
            $userEmail   =   $_POST['email'];
            $messageSubject   =   $_POST['subject'];
            $message   =   $_POST['message'];

            $to =   "[email protected]";
            $body   =   "";

            $body   .=  "From:  ".$userName.    "\r\n";
            $body   .=  "Email:  ".$userEmail.    "\r\n";
            $body   .=  "Message:  ".$message.    "\r\n";

            mail($to,$messageSubject,$body);

            $message_sent   =   true;
    }
}
 ?>

<html lang="en" dir="ltr">

the top of the HTML is at the bottom of this snip, the file name is contact.php (from contact.html) so the htaccess rewrite isn't set up yet.

Below is the html on the same page for the form

<form class="contact-form" action="contact.php" method="POST">

   <input class="contact-form-text" type="text" name="name" id="name" placeholder="Full name" tabindex="1" required>
   <input  class="contact-form-text" type="email" name="email" id="email" placeholder="Your E-mail" tabindex="2" required>
   <input class="contact-form-text" type="text" name="subject" id="subject" placeholder="Subject" tabindex="3" required>

   <textarea class="contact-form-text" name="message" placeholder="Message" tabindex="4"></textarea>

   <button class="contact-form-button" type="submit" name="submit">Send</button>

</form>


Solution

  • Your problem is right here: if(ifsset( Surely you mean if(isset())

    In the future you can add the following two lines of code to the top of a PHP script to help you find errors:

    error_reporting(E_ALL);
    ini_set("display_errors", 1);
    

    Further, you'll notice that you get a HTTP 500 error when you visit your page. This almost always means that you have a syntax error in your PHP code.