title: Send email with attachments with wordpress
body: <p>I'm new to Wordpress and I'm very struggling about this sending an email with attachments :( I don't know what seems to be wrong but I know that I lack some codes.
  Please help me. Thank you very much in advanced! :))</p>
  
  <p>Here is my code which is located on two different files.
  In my index.php</p>
  
  <pre><code>Name (required)&lt;br&gt;         
      &lt;input type="text" class="name"&gt;&lt;/input&gt;
          Email (required)&lt;/br&gt;
          &lt;input type="text" class="e-mail"&gt;&lt;/input&gt;
          Attach Your Resume&lt;/br&gt;
          &lt;input type="file" class="attachment" accept="image/gif, image/jpeg, image/png, application/pdf, application/msword"/&gt;
          &lt;div id ="submit"&gt;&lt;input id="button-submit" type="submit"&gt;&lt;/input&gt;&lt;/div&gt;
          &lt;/div&gt;
  
  
  &lt;script type="text/javascript"&gt;
  $('#button-submit').click(function(){
      var ajaxurl = '&lt;?php echo admin_url('admin-ajax.php'); ?&gt;';
      var names = $('.name').val();
      var emails = $('.e-mail').val();
      var attachments = $('.attachment').val();
      if ( names =="" || emails=="" || attachments == ""){
          alert('You must fill all the required fields!');
      }else{
          var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
          if(pattern.test(emails)){
              /*$('#submit').html('&lt;div class="loader"&gt;&lt;/div&gt;');*/
              jQuery.ajax({
                url: ajaxurl,
                type: 'POST',
                dataType: 'html',
                data: {action: 'resume',
                      txtname: $('.name').val(),
                      txtemail: $('.e-mail').val(),
                      attachment: $('.attachment').val(),
                      },
  
                complete: function(xhr, textStatus) {
  
                },
                success: function(data, textStatus, xhr) {
                  $('#submit').html('Thank you for submitting!');
                  // $('.name').val("");
                  // $('.e-mail').val("");
                  // $('.attachment').val("");
                },
                error: function(xhr, textStatus, errorThrown) {
                }
              }); 
          }
          else{
              alert("Invalid E-mail address format.");
          }
  
      }   
      return false;
  });         
  </code></pre>
  
  <p></p>
  
  <p>This one is located and declared on my functions.php</p>
  
  <pre><code>function resume() {
  $name = $_POST['txtname'];
  $email = $_POST['txtemail'];
  $attachments = $_POST['attachment'];
  $headers = 'From: automailer@sample.ph' . "\r\n" .'Reply-To: automailer@sample.ph' . "\r\n" .'X-Mailer: PHP/' . phpversion();
  $message .= "Contact Details:\n\nName: ".$name."\nEmail: ".$email."\nResume: ";     
          if (file_exists($attachments)) {
              $handle = fopen($attachments, 'r');
  
              $content = fread($handle, filesize($attachments));
  
              fclose($handle);
              $message .= '--' . "\n";
              $message .= 'Content-Type: application/octet-stream; name="' . basename($attachments) . '"' . "\n";
              $message .= 'Content-Transfer-Encoding: base64' . "\n";
              $message .= 'Content-Disposition: attachment; filename="' . basename($attachments) . '"' . "\n";
              $message .= 'Content-ID: &lt;' . basename(urlencode($attachments)) . '&gt;' . "\n";
              $message .= 'X-Attachment-Id: ' . basename(urlencode($attachments)) . "\n" ."\n";
              $message .= chunk_split(base64_encode($content));
          }
          else
          {
              $message .= "Attachment failed to upload.";
          }
  mail("sample@outlook.com", 'Careers', $message,$headers);
  die();
  }
  </code></pre>