Soul Coder
Soul Coder

Reputation: 804

How to attach file while sending email in laravel?

I tried to send email using laravel smtp,

 Mail::send('mail', $data, function($message)  use ($request){
     $message->to($request->input('email'), 'Than Htut')->subject
        ($request->input('subject'));
     $message->attach($request->input('resume'));
     $message->from('[email protected]','My Name');
  });
  echo "HTML Email Sent. Check your inbox.";

the problem is showing like this

Swift_IoException Unable to open file for reading

But if i use attachData like this

  Mail::send('mail', $data, function($message)  use ($request){
     $message->to($request->input('email'), 'Than Htut')->subject
        ($request->input('subject'));
     $message->attachData($request->input('resume'), "haha.pdf");
     $message->from('[email protected]','My Name');
  });
  echo "HTML Email Sent. Check your inbox.";

its work, but cant open file. , enter image description here Here is my fronend part,

<form class="uk-form-stacked" action="{{ url('jobseekers/send') }}" method="post" id="cv_mail_data">
                    <input type="hidden" name="_token" value="{{ csrf_token() }}">
                    <input type="hidden" name="cv_no" value="{{ $jobseekers->id }}">




  <input type="text" placeholder="To" name="email" class="md-input" multiple>
  <input type="text" placeholder="To" name="subject" class="md-input" multiple>
  <input type="file" name="resume" accept="application/pdf,application/vnd.ms-excel" />



                             <div class="uk-grid" data-uk-grid-margin>
                                <div class="uk-width-medium-1-1 parsley-row">
                                    <textarea id="wysiwyg_tinymce" name="cover_letter" cols="30"
                                              rows="20"></textarea>
                                </div>
                            </div>
                             <button type="submit" class="btn btn-primary">
                                Create
                            </button>

please guide me, thanks.

Upvotes: 0

Views: 1208

Answers (1)

First of all, where's your enctype="multipart/form-data" attribute in your form? And second, for retrieving files on laravel you use the file method $request->file('your-file');.

Upvotes: 1

Related Questions