Hi, I'm trying to make a bug report system where the user sends a body of text and OPTIONALLY he can upload a file (image, doc...) along with the text to be sent to my mail inbox.
However, when I only send text I get this error:
"The file must be a file of type: doc, pdf, docx, zip, odt, jpeg, bmp, png, jpg, svg."
how can I fix this, also when I upload a file along with text the mail is sent all right but the attached file is only 1kb, always.
public function contactar_reportar_bug(BugReport $request)
{
$sender_mail = config('globals.admin_mail');//mail sender, in this case it's me
$destination_mail = config('globals.admin_mail');//mail receiver, in this case it's me too
$client_phone = config('globals.client_phone');
$body = $request->body;//bug report mail message
$file = $request->file('file');//bug report screencap or doc
$file_name = $file->getClientOriginalName();//outputs Laravel DOC.odt
$mime_type = $file->getMimeType();//outputs application/
$file_extension = $file->guessExtension();//outputs .odt
$restaurant = Globals::where('name' , 'Nombre del restaurante')->pluck('value');//outputs web_name, used in the mail subject
$subject = "Nuevo reporte de bug en $restaurant";//subject of the mail
$bug = new Bug();
$bug->body = $request->body;
$bug->save();
Mail::to($destination_mail)->send(new BugReportMail($body, $file, $subject, $restaurant, $client_phone, $sender_mail, $file_name, $mime_type));
return response()->json([
'success' => 'Reporte de bug enviado',
'bug' => $bug,
]);
}
Bug Report form request (notice how only the body of the message is required):
public function rules()
{
return [
'body' => 'required|string|min:5',
'file' => 'mimes:doc,pdf,docx,zip,odt,jpeg,bmp,png,jpg,svg|max:2000'
];
}
Getting mimes validation fail when not uploading optional file with AJAX
Hi, I'm trying to make a bug report system where the user sends a body of text and OPTIONALLY he can upload a file (image, doc...) along with the text to be sent to my mail inbox.
However, when I only send text I get this error:
how can I fix this, also when I upload a file along with text the mail is sent all right but the attached file is only 1kb, always.
Jquery code:
Method for sending email:
Bug Report form request (notice how only the body of the message is required):