0
votes

I have created a static website in Rapidweaver (nrgies.com) & have managed to host it on AWS S3 but I get the following error for ONLY my Contact page

404 Not Found

Code: NoSuchKey

Message: The specified key does not exist.

Key: nrgies.s3.eu-west-2.amazonaws.com/error.html RequestId: 3C9DE5ABDA5C6F94 HostId: KWAoZQx1/Iozh3kl+OpzfZaR0DMuVByHKVp1X/sJyM8wASwCEiFIJ5mC4NzzRrPlMjdiCErYkfc=

I have given public access to the bucket as it works with other pages but for some reason it doesn't resolve the Contact form

In my contact_form folder I have an index.php & a folder with mailer.php

index.php is as follows - can someone please guide me in simple language what I am missing here?

index.php:

<?php
    // Start session.
    session_start();
    
    // Set a key, checked in mailer, prevents against spammers trying to hijack the mailer.
    $security_token = $_SESSION['security_token'] = uniqid(rand());
    
    if ( ! isset($_SESSION['formMessage'])) {
        $_SESSION['formMessage'] = 'Please complete the form and a member of our team will contact you.';   
    }
    
    if ( ! isset($_SESSION['formFooter'])) {
        $_SESSION['formFooter'] = ' ';
    }
    
    if ( ! isset($_SESSION['form'])) {
        $_SESSION['form'] = array();
    }
    
    function check($field, $type = '', $value = '') {
        $string = "";
        if (isset($_SESSION['form'][$field])) {
            switch($type) {
                case 'checkbox':
                    $string = 'checked="checked"';
                    break;
                case 'radio':
                    if($_SESSION['form'][$field] === $value) {
                        $string = 'checked="checked"';
                    }
                    break;
                case 'select':
                    if($_SESSION['form'][$field] === $value) {
                        $string = 'selected="selected"';
                    }
                    break;
                default:
                    $string = $_SESSION['form'][$field];
            }
        }
        return $string;
    }
?><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">

<head>

    <meta charset="utf-8" /> 
<link rel="preconnect" href="https://fonts.gstatic.com"> 
<link href="https://fonts.googleapis.com/css2?
family=Archivo:ital,wght@0,400;0,700;1,400;1,700&display=swap" rel="stylesheet">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="description" content="Please complete our enquiry form, email or call us on:
e: [email protected] 
m: 07956 500315" />
        <meta name="robots" content="index, follow" />
        <link rel="apple-touch-icon" sizes="167x167" href="http://nrgies..com/resources/medium.png" />
<link rel="apple-touch-icon" sizes="180x180" href="http://nrgies..com/resources/large.png" />
<link rel="apple-touch-icon" sizes="152x152" href="http://nrgies..com/resources/small.png" />
<link rel="mask-icon" href="http://nrgies..com/resources/NRGies_Blue%20Logo.png" color="rgba(0,0,255,1.00)" /><link rel="icon" type="image/png" href="http://nrgies..com/resources/favicon_medium.png" sizes="32x32" />
<link rel="icon" type="image/png" href="http://nrgies..com/resources/favicon_small.png" sizes="16x16" />
<link rel="icon" type="image/png" href="http://nrgies..com/resources/NRGies_Blue%20Logo.png" sizes="64x64" />

    <meta name="twitter:card" content="summary">
    <meta name="twitter:title" content="NRGies Contact">
    <meta name="twitter:description" content="Please complete our enquiry form, email or call us on:
e: [email protected] 
m: 07956 500315">
    <meta name="twitter:image" content="http://nrgies.ddns.net:8085/resources/Banner.jpg">
    <meta name="twitter:url" content="http://nrgies.ddns.net:8085/contact_form/index.php">
    <meta property="og:type" content="website">
    <meta property="og:site_name" content="NRGies">
    <meta property="og:title" content="NRGies Contact">
    <meta property="og:description" content="Please complete our enquiry form, email or call us on:
e: [email protected] 
m: 07956 500315">
    <meta property="og:image" content="http://nrgies.ddns.net:8085/resources/Banner.jpg">
    <meta property="og:url" content="http://nrgies.ddns.net:8085/contact_form/index.php"> 

    <!-- Meta tags -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />

    <title>NRGies Contact</title>
    <link rel="stylesheet" type="text/css" media="all" href="../rw_common/themes/Mountains/consolidated.css?rwcache=635471980" />
        
        
</head>

<!-- This page was created with RapidWeaver from Realmac Software. http://www.realmacsoftware.com -->

<body>
    <div class="hero" id="hero">
        <nav class="navbar navbar-expand-lg pt-3">
            <div class="container">
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false"
                    aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarNav">
                    <ul class="navbar-nav mr-auto"><li class="nav-item"><a href="../" rel="" class="nav-link">Home</a></li><li class="nav-item has-dropdown"><a href="../page-3/" rel="" class="nav-link dropdown-toggle" data-toggle="dropdown">Services</a><ul class="navbar-nav mr-auto"><li class="nav-item"><a href="../page-3/page-2/" rel="" class="nav-link">IT Services</a></li><li class="nav-item"><a href="../page-3/page-6/" rel="" class="nav-link">Home Automation</a></li><li class="nav-item"><a href="../page-3/page/" rel="" class="nav-link">Energy Management</a></li></ul></li><li class="nav-item"><a href="../page-4/" rel="" class="nav-link">Fees</a></li><li class="nav-item active"><a href="./" rel="" class="nav-link">Contact</a></li></ul>
                </div>
            </div>
        </nav>

        <div class="hero-content" id="hero">
            <div class="container">
                <div class="row">
                    <div class="col">
                        <h1 class="hero-title display-1" data-aos="fade-right" data-aos-delay="300" data-aos-duration="500">Contact</h1>
                        <h2 class="hero-slogan font-italic display-4" data-aos="fade-right" data-aos-delay="350" data-aos-duration="500"></h2>
                    </div>
                </div>
            </div>
        </div>

        <div class="hero-background"></div>
    </div>


    <main class="content">
        <div class="container">
            <div class="row intro justify-content-between">
                <div class="col-sm-8 intro-col" data-aos="fade-right" data-aos-delay="300" data-aos-duration="500">
                    
<div class="message-text"><?php echo $_SESSION['formMessage']; unset($_SESSION['formMessage']); ?></div><br />

<form class="rw-contact-form" action="./files/mailer.php" method="post" enctype="multipart/form-data">
     <div>
        <label>Your Name</label> *<br />
        <input class="form-input-field" type="text" value="<?php echo check('element0'); ?>" name="form[element0]" size="40"/><br /><br />

        <label>Your Email</label> *<br />
        <input class="form-input-field" type="text" value="<?php echo check('element1'); ?>" name="form[element1]" size="40"/><br /><br />

        <label>Subject</label> *<br />
        <input class="form-input-field" type="text" value="<?php echo check('element2'); ?>" name="form[element2]" size="40"/><br /><br />

        <label>Message</label> *<br />
        <textarea class="form-input-field" name="form[element3]" rows="8" cols="38"><?php echo check('element3'); ?></textarea><br /><br />

        <div style="display: none;">
            <label>Spam Protection: Please don't fill this in:</label>
            <textarea name="comment" rows="1" cols="1"></textarea>
        </div>
        <input type="hidden" name="form_token" value="<?php echo $security_token; ?>" />
        <input class="form-input-button" type="reset" name="resetButton" value="Reset" />
        <input class="form-input-button" type="submit" name="submitButton" value="Submit" />
    </div>
</form>

<br />
<div class="form-footer"><?php echo $_SESSION['formFooter']; unset($_SESSION['formFooter']); ?></div><br />

<?php unset($_SESSION['form']); ?>

                </div>
                <div class="sidebar col-sm-4 order-md-8" data-aos="fade-up">
                    <div class="logo" data-aos-delay="450" data-aos-duration="500">
                        <img src="../rw_common/images/NRGies Con_07E6FF Logo.png" width="169" height="76" alt="NRGies"/>
                    </div>

                    <div class="mt-5">
                        <h3 class="sidebar-title">
                            Contact us
                        </h3>
                        Please complete our enquiry form, email or call us on:<br />e: [email protected] <br />m: 07956 500315<br />a: Abbey Court, Abbey Rd, London, NW8 0AU
                        
                    </div>
                </div>
            </div>
        </div>

        <div class="footer">
            <div class="container">
                <div class="row">
                    <div class="col" data-aos="fade-right" data-aos-delay="0" data-aos-duration="500">
                        <div class="footer-content text-center">
                            &copy; Copyright 2010 NRGies Consulting Ltd. All Rights Reserved. <a href="#" id="rw_email_contact">             Contact Me</a><script type="text/javascript">var _rwObsfuscatedHref0 = "mai";var _rwObsfuscatedHref1 = "lto";var _rwObsfuscatedHref2 = ":in";var _rwObsfuscatedHref3 = "fo@";var _rwObsfuscatedHref4 = "nrg";var _rwObsfuscatedHref5 = "ies";var _rwObsfuscatedHref6 = ".co";var _rwObsfuscatedHref7 = "m";var _rwObsfuscatedHref = _rwObsfuscatedHref0+_rwObsfuscatedHref1+_rwObsfuscatedHref2+_rwObsfuscatedHref3+_rwObsfuscatedHref4+_rwObsfuscatedHref5+_rwObsfuscatedHref6+_rwObsfuscatedHref7; document.getElementById("rw_email_contact").href = _rwObsfuscatedHref;</script>
                        </div>

                        <ul class="navbar-nav mr-auto"><li class="nav-item"><a href="../" rel="" class="nav-link">Home</a></li><li class="nav-item has-dropdown"><a href="../page-3/" rel="" class="nav-link dropdown-toggle" data-toggle="dropdown">Services</a></li><li class="nav-item"><a href="../page-4/" rel="" class="nav-link">Fees</a></li><li class="nav-item active"><a href="./" rel="" class="nav-link">Contact</a></li></ul>
                    </div>
                </div>
            </div>
        </div>
    </main>

    <script type="text/javascript" src="../rw_common/themes/Mountains/js/main.js?rwcache=635471980"></script>
</body>

</html>
1

1 Answers

0
votes

A static website means that their is no server-side code that can be executed. PHP is a language that has to be executed on the webserver, which is not supported as @hephalump points out with the reference to this question in the comments.

This means you can't use PHP to create a contact form for a static website in S3 as it requires server side interactions.

The error message you showed us comes from a different source though.

When you set up static website hosting in S3, it allows you to set a website index document and an error document. The index will be the default page if you access the domain and the error document will be displayed in case a user navigates to a key that doesn't exist or other errors.

You're seeing the error message, because error.html, which is the error document you configured, doesn't exist in the bucket. Presumably S3 notices you tried to do something it can't do and thus redirects you to the error document, which doesn't exist.