-1

This is my view.vue file which it included a form to let user to fill in.

<v-form ref="form" lazy-validation style="width:70%;margin:4% auto;" ENCTYPE="text/plain">
       <input type="text" v-model="ob_name">
       <input type="file" ref="file1">
       <v-btn @click="createContact()">Confirm</v-btn>
</v-form>

Then this is my script under view.vue, i've tried to console the file and it works fine which it will show this ( file1: ► File )in DevTools Console.

createContact: function(){
    formData.append('file1', this.file1);
    formData.append('ob_name', this.ob_name);
    this.axios({ 
          method: 'post',
          url: 'http://www.company.com/mail.php',
          data: formData,
          config: { 
          headers: {
                'Content-Type': 
                'multipart/form-data' 
          }}
    })
},

in mail.php. I've also tried to make the input to text instead of file type, it works too. Im able to see the content from the email. The only thing that failed to view is Type="File".

<?php

$file1= "Undefined SSM";
$ob_name = "Undefined name";
if(isset($_POST['file1'])){
    $file1= $_POST['file1'];
    $ob_name = $_POST['ob_name'];
}

$message = "<p>Download the file below</p>";
$message .= "<p>$file1 $ob_name</p>";

$to_email = 'myemail@gmail.com';
$subject = 'New registration';
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=UTF-8';
$headers[] = 'From: Company <noreply@Company.com>';

mail($to_email, $subject, $message, implode("\r\n", $headers));

?>

I really need help, im struggling for this issue for a long time. No idea what to do.

This is the email content i received from the php, it mentioned undefined name

enter image description here

Is this correct for when i clicked the button and trigger the file to mail.php formData.append('ob_ssm', this.file,this.file.name);

"

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
cococrunch
  • 15
  • 7
  • what is the error that you are getting – Hirumina Jul 08 '20 at 06:06
  • I ve upload an image about the data information show in the email – cococrunch Jul 08 '20 at 06:30
  • `$file1= $_POST['file1'];` – file uploads are not made available in $_POST to begin with. Is it really so hard to go and inform yourselves properly on the _absolute basics_ of the techniques/features you are using? https://www.php.net/manual/en/features.file-upload.post-method.php – CBroe Jul 08 '20 at 09:09

1 Answers1

0

To make an attachment downloadable, use this header.

header("Content-Disposition: attachment; filename=${filename}");
Tushar
  • 665
  • 5
  • 11
  • im not sure why, whenever i added the $file1= "Undefined SSM"; anything about the file, I will receive this email Business name Undefined name Undefined SSM – cococrunch Jul 08 '20 at 07:38
  • I think to access file you need to use $_FILES global object instead of $_POST and sorry, but I did not get your last comment. – Tushar Jul 08 '20 at 08:40
  • formData.append('ob_ssm', this.file,this.file.name); – cococrunch Jul 08 '20 at 09:02
  • Btw Thank you so much for helping me, after i changed the $_FILES, all works fine but the attachement still not there yet – cococrunch Jul 08 '20 at 09:04
  • You want to provide an attachment in your mail?? – Tushar Jul 08 '20 at 09:05
  • Yes, i planned to do like when a user send the application form, then me as an admin will be able to review the application form. Including the file document that the user attached – cococrunch Jul 08 '20 at 09:07
  • Have a look at [this](https://stackoverflow.com/questions/12301358/send-attachments-with-php-mail), maybe it could be of some help. – Tushar Jul 08 '20 at 09:09
  • Oh okay, 1 more question. Is there anyway the easiest way to allow admin to download from the whatever place (email or admin page)?? I checked the phpmyadmin database for the file part, it shown Array. Im not sure why. – cococrunch Jul 08 '20 at 09:23