I got to make this contact form works using phpmailer, but I need to separate php and html code completely. I need this because I intent the contact form to be the last section of a index.html web page, so I need this contact form to be .html and I am aware that if I include a single line of php code in it, it must be .php in order to work
The core of the question es how to remove this line of php
<?php if ($msg != "") echo "$msg<br><br>"; ?>
and keep being the success and error message????
Here the php 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'];
if (isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != "") {
$file = "attachment/" . basename($_FILES['attachment']['name']);
move_uploaded_file($_FILES['attachment']['tmp_name'], $file);
} else
$file = "";
$mail = new PHPMailer();
//if we want to send via SMTP
$mail->Host = "localhost";
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Username = "kk@prisa.com";
$mail->Password = "1234";
$mail->SMTPSecure = "false"; //TLS
$mail->Port = 587; //587
$mail->addAddress('kk@prisa.com');
$mail->setFrom($email);
$mail->Subject = $subject;
$mail->isHTML(true);
$mail->Body = $message;
$mail->addAttachment($file);
if ($mail->send())
$msg = "Your email has been sent, thank you!";
else
$msg = "Please try again!";
unlink($file);
}
?>
Here the html code with the damn php line:
<?php if ($msg != "") echo "$msg<br><br>"; ?>
<form method="post" action="index.php">
<input class="form-control" name="subject" placeholder="Subject..."><br>
<input class="form-control" name="email" type="email" placeholder="Email..."><br>
<textarea placeholder="Message..." class="form-control" name="message"></textarea><br>
<input class="form-control" type="file" name="attachment"><br>
<input class="btn btn-primary" name="submit" type="submit" value="Send Email">
</form>