title: PHPMailer Contact form - Contact form. Errors after opening the page
body: <p>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.</p>
  
  <p>Notice: Undefined index: attachmentFile in C:\xampp\htdocs\Test\e-mail2\index.php on line 74</p>
  
  <p>and</p>
  
  <p><code>$mail-&gt;AddAttachment($_FILES['attachmentFile']['tmp_name'],$_FILES['attachmentFile']['name']);</code></p>
  
  <p>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</p>
  
  <p><code>$mail-&gt;SetFrom($_POST["userEmail"], $_POST["userName"]);</code></p>
  
  <pre><code>&lt;body&gt;
  &lt;form id="frmContact" action="" method="post"&gt;
  &lt;div id="mail-status"&gt;&lt;/div&gt;
  
  &lt;div&gt;
  &lt;label style="padding-top: 20px;"&gt;Name&lt;/label&gt; &lt;span
  id="userName-info" class="info"&gt;&lt;/span&gt;&lt;br /&gt; 
  &lt;input type="text" name="userName" id="userName" class="demoInputBox"&gt;
  &lt;/div&gt;
  
  &lt;div&gt;
  &lt;label&gt;Email&lt;/label&gt; &lt;span id="userEmail-info" class="info"&gt;&lt;/span&gt;&lt;br /&gt;
  &lt;input type="text" name="userEmail" id="userEmail" class="demoInputBox"&gt;
  &lt;/div&gt;
  
  &lt;div&gt;
  &lt;label&gt;Attachment&lt;/label&gt;&lt;br /&gt; 
  &lt;input type="file" name="attachmentFile" id="attachmentFile" class="demoInputBox"&gt;
  
  &lt;/div&gt;
  &lt;div&gt;
  &lt;label&gt;Subject&lt;/label&gt; &lt;span id="subject-info" class="info"&gt;&lt;/span&gt;&lt;br /&gt;
  &lt;input type="text" name="subject" id="subject" class="demoInputBox"&gt;
  &lt;/div&gt;
  
  &lt;div&gt;
  &lt;label&gt;Content&lt;/label&gt; &lt;span id="content-info" class="info"&gt;&lt;/span&gt;&lt;br /&gt;
  &lt;textarea name="content" id="content" class="demoInputBox" cols="60" rows="6"&gt;&lt;/textarea&gt;
  &lt;/div&gt;
  
  &lt;div&gt;
  &lt;input type="submit" value="Send" class="btnAction" /&gt;
  &lt;/div&gt;
  &lt;/form&gt; 
  
  &lt;?php 
  
  use PHPMailer\PHPMailer\PHPMailer; 
  use PHPMailer\PHPMailer\Exception; 
  
  require 'vendor/autoload.php'; 
  
  $mail = new PHPMailer(true); 
  
  try { 
  $mail-&gt;IsSMTP();
  $mail-&gt;SMTPDebug = 2;
  $mail-&gt;SMTPAuth = TRUE;
  $mail-&gt;SMTPSecure = "ssl";
  $mail-&gt;Port     = 465;  
  $mail-&gt;Username = "serwer1999.home.pl";
  $mail-&gt;Password = "password";
  $mail-&gt;Host     = "serwer1999";
  $mail-&gt;Mailer   = "smtp";
  $mail-&gt;SetFrom($_POST["userEmail"], $_POST["userName"]);
  $mail-&gt;AddReplyTo($_POST["userEmail"], $_POST["userName"]);
  $mail-&gt;AddAddress("agniecha@agamazur.pl");  
  $mail-&gt;Subject = $_POST["subject"];
  $mail-&gt;WordWrap   = 80;
  $mail-&gt;MsgHTML($_POST["content"]);
  
  if(is_array($_FILES)) {
  $mail-&gt;AddAttachment($_FILES['attachmentFile']['tmp_name'],$_FILES['attachmentFile']['name']); 
  }
  
  $mail-&gt;IsHTML(true);
  $mail-&gt;send(); 
  echo "Successful"; 
  } catch (Exception $e) { 
  echo "Ups :( {$mail-&gt;ErrorInfo}"; 
  } 
  ?&gt;                  
  &lt;/body&gt;```
  </code></pre>