; $attachmentPath = storage_path('app/public/sample.pdf'); // 确保文件路径正确 Mail::to('recipient@example.com')->send(new SampleMailWithAttachment($content, $attachmentPath)); return back()->with('success', '
Route::get('sendbasicemail','MailController@basic_email');Route::get('sendhtmlemail','MailController@html_email');Route::get('sendattachmentemail','MailController@attachment_email'); PHP Copy 步骤8- 访问以下URL以测试基本邮箱功能。 http://localhost:8000/sendbasicemail PHP Copy 步骤9− 输出...
public function attachmentsEmail(Request $request){ $shipment = Shipment::findOrFail($request->shipmentID); $attachment = Shipment_Attachment::findOrFail($request->attachmentID); $storagePath = Storage::url($attachment->attachmentPath); $email = $request->email; Mail::to($email)->send(new shi...
publicfunctionattachmentsEmail(Request$request){$shipment=Shipment::findOrFail($request->shipmentID);$attachment=Shipment_Attachment::findOrFail($request->attachmentID);$storagePath=Storage::url($attachment->attachmentPath);$email=$request->email;Mail::to($email)->send(newshipmentAttachments($shipment,$...
}publicfunction attachment_email() {$data=array('name'=>"Virat Gandhi");Mail::send('mail',$data, function($message) {$message->to('abc@gmail.com','Tutorials Point')->subject('Laravel Testing Mail with Attachment');$message->attach('C:\laravel-master\laravel\public\uploads\image.png')...
将文件附加到邮件时,你还可以使用 as 和withMime 方法指定附件的显示名称和 / 或 MIME 类型:/** * 获取邮件的附件 * * @return array<int, \Illuminate\Mail\Mailables\Attachment> */ public function attachments(): array { return [ Attachment::fromPath('/path/to/file') ->as('name.pdf') ->...
一旦数据被传递到 with 方法,同样的它将自动在视图中可用,因此可以像访问 Blade 模板中的任何其他数据一样访问它: Price: {{ $orderPrice }}附件要向电子邮件添加附件,你将向邮件的 attachments 方法返回的数组添加附件。首先,可以通过向 Attachment 类提供的 fromPath 方法提供文件路径来添加附件:use Illuminate...
* * @return \Illuminate\Mail\Attachment */ public function toMailAttachment() { return Attachment::fromPath('/path/to/file'); } }Once you have defined your attachable object, you may simply pass an instance of that object to the attach method when building an email message:...
$attachment = Shipment_Attachment::findOrFail($request->attachmentID); $storagePath = Storage::url($attachment->attachmentPath); $email = $request->email; Mail::to($email)->send(new shipmentAttachments($shipment, $attachment, $storagePath)); //maybe try to use queue instead of send... ...
Mail::to($email)->send(new shipmentAttachments($shipment, $attachment, $storagePath)); //maybe try to use queue instead of send... return back(); } So I'm not sure where this could be coming from. 解决方法: Try to use public_path() laravel helper function instead of '/public'....