The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> Need Confirmation Message to Remain on Page
chome4
post 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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
CharlesEF
post Aug 23 2019, 11:18 AM
Post #2


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



When I try to load the contact.php page I get this error: [23-Aug-2019 16:12:08 UTC] PHP Parse error: syntax error, unexpected '[' in F:\xxxx\xxxx\xxxx\test\PHPMailer\PHPMailer.php on line 288

I have to leave right now but I'll look at the code tonight.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
chome4
post Aug 23 2019, 12:20 PM
Post #3


Newbie
*

Group: Members
Posts: 19
Joined: 6-April 16
Member No.: 24,129



QUOTE(CharlesEF @ Aug 23 2019, 11:18 AM) *

When I try to load the contact.php page I get this error: [23-Aug-2019 16:12:08 UTC] PHP Parse error: syntax error, unexpected '[' in F:\xxxx\xxxx\xxxx\test\PHPMailer\PHPMailer.php on line 288

I have to leave right now but I'll look at the code tonight.


In 'contact.php', lines 21, 22 and 26 need an email address for your hosting account and its password:

$mail->Username = "EMAIL FROM HOST";
$mail->Password = "PASSWORD";
$mail->SMTPSecure = "ssl"; //TLS
$mail->Port = 465; //587

$mail->addAddress('SAME EMAIL');
$mail->setFrom($email);

If you have, let's say, godaddy as your hoster and your email is 'jeff@godaddy.com', then you would use that email and its corresponding password. contact.php would live on the hosters server, so it's contents would be protected, hopefully....

This method, SMTP, seems to be the only way I know of to recieve an email from someone with a yahoo account!

If you are going to zip and send files back, please remember to amend the above lines to remove your details!

Thanks for your ongoing help.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th March 2024 - 06:19 PM