Need Confirmation Message to Remain on Page |
Need Confirmation Message to Remain on Page |
chome4 |
Aug 22 2019, 09:03 AM
Post
#1
|
Newbie Group: Members Posts: 19 Joined: 6-April 16 Member No.: 24,129 |
I have a working php contact form:
<?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 = "email"; $mail->Password = "password"; $mail->SMTPSecure = "ssl"; //TLS $mail->Port = 465; //587 $mail->addAddress('email'); $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!"; } ?> The confirmation message is echoed out to a new, white page. Still getting to grips with php, but I cannot work out how to get the confirmation message to appear above the form instead of appearing on a new page. This is the form's code <form method="post" action="contact.php" enctype="multipart/form-data"> <input name="subject" placeholder="Subject..."><br> <input name="email" type="email" placeholder="Email..."><br> <textarea placeholder="Message..." name="message"></textarea><br> <input name="submit" type="submit" value="Send Email"> </form> Any ideas? Hope someone can help. |
CharlesEF |
Aug 23 2019, 11:17 PM
Post
#2
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
Attached is another version of your contact form. This version combines both HTML and PHP into 1 file. Be sure to modify your PHPMailer stuff before you load the page. Once the page is loaded leave both fields blank and click Submit. You should see a error message below each field. Then enter valid data and click Submit. Let me know what happens.
example.php ( 2.31k ) Number of downloads: 410 |
chome4 |
Aug 24 2019, 03:32 AM
Post
#3
|
Newbie Group: Members Posts: 19 Joined: 6-April 16 Member No.: 24,129 |
Attached is another version of your contact form. This version combines both HTML and PHP into 1 file. Be sure to modify your PHPMailer stuff before you load the page. Once the page is loaded leave both fields blank and click Submit. You should see a error message below each field. Then enter valid data and click Submit. Let me know what happens. example.php ( 2.31k ) Number of downloads: 410 This one worked perfectly! I separated the above into index.php and 'sendmail.php'. I used the php include to call the sendmail file before the form code. I've incorporated it into the site I'm working on: http://test.ericfinlayartist.co.uk/index.php Apart from tidying things up, the only outstanding issue that has arisen is the page flying to the top after you click submit! I've had this before and will search through my history to find the solution. Thanks for all your help. |
Lo-Fi Version | Time is now: 26th April 2024 - 12:49 PM |