Я пытаюсь отправить электронное письмо с вложением в laravel 5.8, используя уценку. Это работает просто отлично электронной почте без вложений. Как я могу получить отправку с вложением?
Вид формы:
<form action="{{url('deputyheadteacher-email')}}" method="post" enctype="multipart/form- data">
{{csrf_field()}}
<div class="box-body">
<div class="form-group">
<input type="text" class="form-control" name="subject" placeholder="Subject" required/>
</div>
<div class="form-group">
<textarea class="textarea" name="message" placeholder="Message" required
style="width: 100%; height: 125px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;"></textarea>
</div>
<div class="form-group">
<input type="file" id="att" name="att"/>
</div>
</div>
<div class="box-footer clearfix">
<button class="pull-right btn btn-default" id="sendEmail">Send <i class="fa fa-arrow-circle-right"></i></button>
</div>
</form>
Контроллер:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Session;
use App\User;
use Auth;
use Input;
use App\Mail\DeputyHeadTeacherMailAll;
use Illuminate\Support\Facades\Mail;
class DeputyHeadTeacherEmailController extends Controller
{
public function mail(Request $request)
{
$users = User::all();
$user = Auth::user();
$fname = $user->fname;
$sname = $user->sname;
$role = $user->role->name;
$file = $request->file('att');
$file1 = $request->att;
f($request->hasFile('att'))
{
$image = $request->file('att');
$name = time().'.'.$image->getClientOriginalExtension();
$destinationPath = public_path('/files/');
$image->move($destinationPath, $name);
}
else
{
$name = "";
}
//exit();
//echo $file1." - ".$file; exit();
$mime = 'image/png';
$display = 'campaign';
$data = array(
'subject' => $request->subject,
'bodyMessage' => $request->message,
'attachment' => $file,
'attachment1' => $file1,
'name' => $name,
'mime' => $mime,
'display' => $display,
'fname' => $fname,
'sname' => $sname,
'role' => $role,
);
foreach($users as $user)
{
$email = $user->email;
Mail::to($email)->send(new DeputyHeadTeacherMailAll($data));
}
/*
Mail::send('emails/deputyheadteachersendalll',$data,function($message)
{
$message->to('mikejosephm52@gmail.com')->subject('Test123');
$message->from('info@brightrock.co.ke');
});*/
Session::flash('success','Your email was sent!!!');
return back();
}
}
Отправляемый по почте:
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\User;
class DeputyHeadTeacherMailAll extends Mailable
{
use Queueable, SerializesModels;
public $data;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($data)
{
//
$this->data = $data;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
//return $this->view('emails.deputyheadteachersendalll')->attach('files/'.$this->data['name']);
//return $this->markdown('emails.deputyheadteachersendall')->subject($this->data['subject']);
return $this->markdown('emails.deputyheadteachersendall')->attach('files/1587758910.jpg')->subject($this->data['subject']);
}
}
Для вышеупомянутая сборка FX, вторая закомментированная строка работает, хотя отправляет без вложения Последняя строка - это попытка отправить с пи c из папки public / files.
Последнее, но не менее важное, config / filesystems:
'disks' =>
[
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
],
],
Ваша помощь очень ценится