title: Take Input Type File (HTML) to JavaScript and Send an Email Using PHPmailer
body: <p>i'm using PHPMailer, JavaScript and PHP, through my code i send the email to specific user, next step is attach a file with the email.</p>
  
  <p>But i have two questions about that:</p>
  
  <ol>
  <li>first one is related with the following code:</li>
  </ol>
  
  <p>HTML part:</p>
  
  <pre><code>&lt;input type="file" name="myFile" id="myFile" required/&gt;
  </code></pre>
  
  <p>I'm using this one to attach the file, part of the email</p>
  
  <p>JavaScript part, my function to send email (so far i can send an email with test data)</p>
  
  <pre><code>function SendMail(){
      var cod="1234"; var subject="hello my friend";
      $.get("SendMail.php?cod="+cod+"&amp;subject="+subject+""); // (1)
  }
  </code></pre>
  
  <p>In (1) how can i send the input file attached to my php file?</p>
  
  <p>Like,</p>
  
  <pre><code>    $.get("SendMail.php?cod="+cod+"&amp;subject="+subject+"&amp;mail="FileRelatedWithInputID);
  </code></pre>
  
  <ol start="2">
  <li>When i got successfully the file in PHP, how have i to format it to attach it to the email using PHPMailer?</li>
  </ol>
  
  <p>That's it, my two questions about this issue, i appreciate your answers and suggestions. </p>
  
  <p>Thank you for your time and attention.</p>
  
  <p>Edited:</p>
  
  <p>My PHP file:</p>
  
  <pre><code>require '../PHPMailer_5.2.4/PHPMailerAutoload.php';
  $server = "localhost";
  $user = "root";
  $pass = "pass";
  $bd = "BD";
  $strHTML1=$_GET["cod"];
  $strHTML2=$_GET["subject"];
  
  
   // HOW DO I _GET THE FILE FROM JS AND FORMAT FILE PROPERLY TO THE MAIL?
  
  
  $strHTML3= $strHTML1.$strHTML2;
  
  $mail="mail@gmail.com";
  
  session_start(); 
  
  $conexion = mysqli_connect($server, $user, $pass,$bd) 
  or die("ERROR");
  
   $mail = new PHPMailer();
   $mail-&gt;isSMTP();
   $mail-&gt;CharSet = "UTF-8";
   $mail-&gt;SMTPDebug = 2;
   $mail-&gt;Mailer = "smtp";
   $mail-&gt;WordWrap = 50;  
   $mail-&gt;PluginDir = "../tickets/PHPMailer_5.2.4/";
   $mail-&gt;Debugoutput = 'html';
   $mail-&gt;Host = 'smtp.gmail.com';
   $mail-&gt;Port = 465;
   $mail-&gt;SMTPSecure = 'ssl';
   $mail-&gt;SMTPAuth = true; 
   $mail-&gt;Username = "mail@site.com.en";  
   $mail-&gt;Password = "12345";
   $mail-&gt;SMTPSecure = 'ssl';  
   $headers = "MIME-Version: 1.0\r\n";
   $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
   $headers .= "From:Home\r\n"; 
   $mail-&gt;AddAddress($mail, "test");
   $mail-&gt;isHTML(true); 
   $mail-&gt;Subject = $strHTML2;
   $mail-&gt;Body    =$strHTML3;
  
  
  
   if(!$mail-&gt;send()) {
       echo 'Message could not be sent.';
       echo 'Mailer Error: ' . $mail-&gt;ErrorInfo.'  ';
       exit;
     }
   $close = mysqli_close($conexion) 
   or die("ERROR");
  </code></pre>