What's new
HTML Forums | An HTML and CSS Coding Community

Welcome to HTMLForums; home of web development discussion! Please sign in or register your free account to get involved. Once registered you will be able to connect with other members, send and receive private messages, reply to topics and create your very own. Our registration process is hassle-free and takes no time at all!

PHP Contact Form: Making Confirmation Appear above Form.

chome4

New member
I have a perfectly working PHP contact form, shown below. My issue is how to change the code so that the confirmation will appear above the form. Instead, after the form has been filled in, the confirmation is printed on a new, blank page. Still learning php but have been struggling with this one!

Hope someone can help.

Cheers....

Code:
<?php
    $msg = "";
    use PHPMailer\PHPMailer\PHPMailer;
    include_once "PHPMailer/PHPMailer.php";
    include_once "PHPMailer/Exception.php";
    include_once "PHPMailer/SMTP.php";

    if (isset($_POST['submit'])) {
        $subject = $_POST['subject'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $mail = new PHPMailer();

        //if we want to send via SMTP
        $mail->Host = "smtp.34sp.com";
        //$mail->isSMTP();
        $mail->SMTPAuth = true;
        $mail->Username = "XXXXXXXXXXXXXXX";
        $mail->Password = "XXXXXX";
        $mail->SMTPSecure = "ssl"; //TLS
        $mail->Port = 465; //587

        $mail->addAddress('XXXXXXXXXX');
        $mail->setFrom($email);
        $mail->Subject = $subject;
        $mail->isHTML(true);
        $mail->Body = $message;
        //$mail->addAttachment($file);

        if ($mail->send())
           echo "<h1>Sent Successfully! Thank you"." ".$name.", We will contact you shortly!</h1></br>
      Use the 'back' arrow to go back to the main page...";
        else
            echo "Something went wrong!";

        
    }
?>
 
Back
Top