I need your help. I create a contact form for a website with the help of the PHPMailer library (ver 6.1). How to correct the code so that no errors appear (below) And how to run this php code in the form from a separate php file. Thank you in advance for your help.
Notice: Undefined index: attachmentFile in C:\xampp\htdocs\Test\e-mail2\index.php on line 74
and
$mail->AddAttachment($_FILES['attachmentFile']['tmp_name'],$_FILES['attachmentFile']['name']);
Notice: Undefined index: userEmail in C:\xampp\htdocs\Test\e-mail2\index.php on line 66 Notice: Undefined index: userName in C:\xampp\htdocs\Test\e-mail2\index.php on line 66
$mail->SetFrom($_POST["userEmail"], $_POST["userName"]);
<body>
<form id="frmContact" action="" method="post">
<div id="mail-status"></div>
<div>
<label style="padding-top: 20px;">Name</label> <span
id="userName-info" class="info"></span><br />
<input type="text" name="userName" id="userName" class="demoInputBox">
</div>
<div>
<label>Email</label> <span id="userEmail-info" class="info"></span><br />
<input type="text" name="userEmail" id="userEmail" class="demoInputBox">
</div>
<div>
<label>Attachment</label><br />
<input type="file" name="attachmentFile" id="attachmentFile" class="demoInputBox">
</div>
<div>
<label>Subject</label> <span id="subject-info" class="info"></span><br />
<input type="text" name="subject" id="subject" class="demoInputBox">
</div>
<div>
<label>Content</label> <span id="content-info" class="info"></span><br />
<textarea name="content" id="content" class="demoInputBox" cols="60" rows="6"></textarea>
</div>
<div>
<input type="submit" value="Send" class="btnAction" />
</div>
</form>
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->Username = "serwer1999.home.pl";
$mail->Password = "password";
$mail->Host = "serwer1999";
$mail->Mailer = "smtp";
$mail->SetFrom($_POST["userEmail"], $_POST["userName"]);
$mail->AddReplyTo($_POST["userEmail"], $_POST["userName"]);
$mail->AddAddress("agniecha@agamazur.pl");
$mail->Subject = $_POST["subject"];
$mail->WordWrap = 80;
$mail->MsgHTML($_POST["content"]);
if(is_array($_FILES)) {
$mail->AddAttachment($_FILES['attachmentFile']['tmp_name'],$_FILES['attachmentFile']['name']);
}
$mail->IsHTML(true);
$mail->send();
echo "Successful";
} catch (Exception $e) {
echo "Ups :( {$mail->ErrorInfo}";
}
?>
</body>```