Level 27
Jan 26, 2021
6
Level 4
is it possible using synch uploaded file stored in storage and send to the mail.
while i will upload a file from frontend. file will be saved in storage folder and path will be saved in database and file send to the mail .??please answer. if possible please share some helpful reference.
Level 4
sir i already try that but file is not sending to mail simultaneously..
Level 27
@redroseamit What do you mean? Show us what you've tried and I am sure we are able to help.
Level 4
public function build(Request $request)
{
//dd ($this->data['file']);
$this->data['file']= $request->all();
if($request->hasFile('file'))
{
$file = $request ->file('file');
$fileName = $file->getClientOriginalName();
$destinationPath = config('storage/app/image/').'/'.$fileName;
$uploads = Storage::put($destinationPath,file_get_contents($file->getRealPath()));
}
dd ($this->data['file']);
return $this->from('[email protected]')
->subject('New Estimate Enquiry received')
->view('users.estimatetomail')
->attachData($this->data['file']->getRealPath(),
array(
'as'=>'file.' . $this->data['file']->getClientOriginalName(),
'mime' => $this->data['file']->getMimeType())
)
->with('data', $this->data);
}
}
while i am doing dd
array:11 [▼
"_token" => "Q4a9MPoJjVx8CeqSzr8pvPIUY1Rc7vLBGl3u9ENt"
"name" => "amit"
"email" => "[email protected]"
"contact" => "hejdkfjd"
"country" => "inhjh"
"other" => "dfdfdf"
"budget" => "000 - 000"
"webdev" => "1"
"marketing" => "1"
"details" => "jhjhjhjhjh"
"image" => Illuminate\Http\UploadedFile {#1330 ▼
-test: false
-originalName: "GAll.pdf"
-mimeType: "application/pdf"
-error: 0
#hashName: null
path: "C:\xampp\tmp"
filename: "php7E3B.tmp"
basename: "php7E3B.tmp"
pathname: "C:\xampp\tmp\php7E3B.tmp"
extension: "tmp"
realPath: false
writable: false
readable: false
executable: false
file: false
dir: false
link: false
}
]
Level 27
@redroseamit Okay, that doesn't like right. A most basic example would look like:
public function build(Request $request)
{
// Do your validations
$filePath = $request->file('file')->store('your/upload/path');
// Create an entry in database or whatever
Mail::to('[email protected]')->send(new TestMail($filePath));
...
}
While the build() function of TestMail looks like:
public function build()
{
return $this->markdown('emails.test.mail')->attachFromStorage($this->filePath);
}
filePath being the file path you passed into __construct of your TestMail Mailable of course.
Level 4
sir what is the seen behind it .,,,
#hashName: null
path: "C:\xampp\tmp"
filename: "php7E3B.tmp"
basename: "php7E3B.tmp"
pathname: "C:\xampp\tmp\php7E3B.tmp"
extension: "tmp"
realPath: false
writable: false
readable: false
executable: false
file: false
dir: false
link: false
}
]
Please or to participate in this conversation.