Hi all,how do i link lets say thankyou.html page to my conatct.html page,so the idea is after submiting the page,by pressing the
submit button,the confirmation page should pop up. Thank you.
Part two - how to set up php so the request/submited page is sent to my email

Hi all,how do i link lets say thankyou.html page to my conatct.html page,so the idea is after submiting the page,by pressing the
submit button,the confirmation page should pop up. Thank you.

You would set the action attribute of the form element to "thankyou.html", if that's where you wish the form to submit to.

contact.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Form Example</title>
    </head>

    <body>
        <form action="thankyou.html">
            <input type="email" name="email" placeholder="Enter your email address." />
            <input type="text" name="subject" placeholder="Email Subject" />
            <textarea name="body" placeholder="Say something..."></textarea>
            <button type="submit">Send</button>
        </form>
    </body>
</html>

Part two - how to set up php so the request/submited page is sent to my email

There are many ways this can be done. I'll demonstrate one simple way:

Edit your contact form so that it points to the right file (thankyou.php, not thankyou.html- assuming a conventional web server configuration) and make it use HTTP POST instead of HTTP GET.

<form action="thankyou.php" method="post">

Then, in thankyou.php:

<?php

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $returnEmail = (!empty($_POST['email']) ? htmlentities($_POST['email']) : '');
    $subject = (!empty($_POST['subject']) ? htmlentities($_POST['subject']) : null);
    $body = (!empty($_POST['body']) ? htmlentities($_POST['body']) : null);

    if ($subject && $body) {
        mail('you@yourdomain.tld', $subject, "{$body}\n\nReturn email: {$returnEmail}");
    }
}

?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Form Example</title>
    </head>

    <body>
        <p>Thank you</p>
    </body>
</html>

What we're doing is checking to see if the page has been requested via HTTP POST (it will have been if the form was submitted). We then go through the fields we have setup in contact.html, checking for values. If a value is found then it's sanitized and stored in a variable. If it has not been set we either store an empty string ($returnEmail, as it's not required per this example) or set the variable to null ($subject and $body, both required) to easily check for validity.

Because our required fields will either have a string value (true) or a null value (false), we can check to make sure they are both true very easily. We do that in the conditional. If that passes then use PHP's mail() function to send the email.

You're going to need to modify this to fit your needs. I don't know what data you're collecting in your form, or the name attributes for those elements. And I don't know what fields are required and which are not. So this example is just that- an example.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.