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

Dani AI

Generated

— good question. is on the right track: send the form to a server script (use POST) and have that script send the mail, then send the user to a thank-you page with an HTTP redirect so a browser refresh won't re-submit the form. Below is a compact, safer server-side pattern that fills gaps left in earlier replies: validate inputs, block header-injection, check mail() success, and always redirect after processing.

<?php
// submit.php
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    header('Location: contact.html');
    exit;
}

$email   = trim($_POST['email'] ?? '');
$subject = trim($_POST['subject'] ?? '');
$body    = trim($_POST['body'] ?? '');
$errors  = [];

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    $errors[] = 'Invalid email';
}
if ($subject === '' || $body === '') {
    $errors[] = 'Missing subject or message';
}
// simple header-injection guard
if (preg_match("/[\r\n]/", $email) || preg_match("/[\r\n]/", $subject)) {
    $errors[] = 'Bad input detected';
}

if ($errors) {
    session_start();
    $_SESSION['form_errors'] = $errors;
    header('Location: contact.html');
    exit;
}

$to = 'you@yourdomain.tld';
$headers = "From: no-reply@yourdomain.tld\r\nReply-To: {$email}\r\n";
$sent = mail($to, $subject, $body, $headers);

if ($sent) {
    header('Location: thankyou.html');
    exit;
}
error_log('Mail failed: ' . print_r($_POST, true));
header('Location: contact.html?error=1');
exit;
?>

Notes and troubleshooting: if mail() fails on your host, use a library like PHPMailer or SwiftMailer with SMTP credentials (more reliable and supports authentication). Always perform server-side checks even if you use HTML5 required attributes or client-side JS. Add CSRF tokens and a spam control (CAPTCHA or rate limits). For a “popup” confirmation without leaving the page, use AJAX to post to the script and show a client-side success message instead of a redirect.

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.