Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Mego's avatar
Level 1

Sending data from inputs to mail

Hi, I am solving an issue about sending mail in Laravel (in Vanilla this is a job for a few minutes).

I have created a form BugReport, classic way - BugReportController@index and @report. @index will render the form, @report should process (so validate and authorize user's inputs) and send it to main application mail (so static mail address, not user's e-mail).

I have created a new Mailable by Artisan with a name "BugReport". However I really don't know how to pass data from inputs to it?

In my BugReportController@report I have something like this:

public function report(ReportBug $request) {
        $validatedData = $request->validated();
        if($validatedData) {
            Mail::to('[email protected]')->send(new BugReport($validatedData));
        }

and in my Mailable I have this:

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class BugReport extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct()
    {

    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->from('[email protected]')
            ->view('emails.bugreport')
            ->with([
                'data' => $validatedData,
            ]);
    }
}

However $validatedData doesn't exists in Mailable class. I know that not, but I would like to ask how to do, desired data will be in Mailable? I have prepared them in BugReportController.

Thank you

0 likes
1 reply
Snapey's avatar

in the mailable, accept the data

    public $validatedData

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($validatedData)
    {
        $this->validatedData = $validatedData;
    }

Now, in your view, you will have access to the $validatedData

Please or to participate in this conversation.