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....
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!";
}
?>