I
I
Ivan Shulga2020-06-18 22:06:18
WordPress
Ivan Shulga, 2020-06-18 22:06:18

How to send file with ajax to mail using PHPMAILER?

only the string "array" is sent

<form action="POST" class="contacts-form" id="formFile">
<label class="label-input-wrapper">
<input name="name" id="input-name" type="text" autocomplete="off" required>
</label>
<label class="label-input-wrapper">
<input name="number" id="input-phone" type="text" autocomplete="off" required>
</label>
<label class="label-input-wrapper">
<input  name="mail" id="input-mail" type="text" autocomplete="off">
</label>
<label class="label-input-wrapper">
<input  name="input-file" id="input-file" type="file" autocomplete="off" required>
</label>
<button class="btn btn-contacts-form">Отправить</button>
</form>


$(function() {
  $("#formFile").submit(function(e) {
      e.preventDefault();
        var $that = $(this),
        formData = new FormData($that.get(0));
    return $.ajax({
      url: "https://site/mail-file.php",
      type: "POST",
      data: formData,
      contentType: false,
      processData: false,
      success: function() {
        jQuery("#formFile")[0].reset();
      }
    }), !1 
  })
})


<?php
$to = '';
$subject = 'Новая заявка с сайта';
$message = "Имя:  {$_POST['name']}\r\n
Почта:  {$_POST['mail']}\r\n
Номер:  {$_POST['number']}\r\n
{$_FILES['input-file']}";
  
define( 'WP_USE_THEMES', false );
require( 'wp-load.php' );
  
$sent_message = wp_mail( $to, $subject, $message );
 
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Wells, 2020-06-18
@Alex_Wells

{$_FILES['input-file']}";
I wonder what conclusion you expected from this?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question