Laravel 11 表单数据未传递到电子邮件模板

问题描述 投票:0回答:1

我对使用 Laravel 相当陌生。但问题就在这里,我遇到一个问题,即单击提交后从表单获取的数据没有传递到刀片模板。例如,电子邮件发送到电子邮件地址,但在电子邮件内部,表单中的姓名不会显示在电子邮件中。我应该说我正在使用 Laravel 和 Livewire。

first_name 的输入之一:

 <x-wui-input wire:model="first_name" placeholder="First Name" label="First Name *[Required]" type="text" id="firstName" name="first_name" class="block w-full px-4 py-4 mx-1 mt-1 border-gray-300 rounded-md focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" />

电子邮件刀片模板:

<div class="p-4 bg-white rounded-lg shadow-md">
    <h2 class="mb-4 text-2xl font-bold text-gray-800">Thank You for Submitting a Good Deed!</h2>
    <p class="mb-2 text-gray-600">Thank you {{$data['first_name']}} {{$data['last_name']}}  for nomination for the annual Chasing Good Award.</p>
</div>

表单组件(提交方法):

public function submit(Request $request)
    {
        $this->validate();

        $data = [
            'first_name' => $request->first_name,
            'last_name' => $request->last_name,
            'nominee_name' => $request->nominee_name
        ];

        Nomination::create(
            $this->only([
                'first_name',
                'last_name',
                'email_address',
                'phone_number',
                'nominating_category',
                'nominee_name',
                'nominee_email',
                'nj_county',
                'story_essay',
                'uploaded_video',
                'disclaimer_agreed'
            ])
        );

        // Create a new Mailable instance
        $mailable = new ThankYouMailable($data);
        $mailabe2 = new NominationMailable($data);
        $mailable3 = new ThankYouSelfMailable($data);

        if ($this->email_address == $this->nominee_email) {
            Mail::to($this->email_address)->send($mailable3);
        } else {
            Mail::to($this->email_address)->send($mailable);
            Mail::to($this->nominee_email)->send($mailabe2);
        }

        session()->flash('message', 'Good deed submitted successfully!');

        return back()->with('message', 'Good deed submitted successfully!');
    }

可邮寄类别:

class ThankYouSelfMailable extends Mailable
{
    use Queueable, SerializesModels;

    public $data;

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

    public function build()
    {
        return $this->view('emails.thank_you_self_nominator')->with($this->data, $this->data);
    }

    /**
     * Get the message envelope.
     */
    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'Thank You For Submitting',
        );
    }

    /**
     * Get the message content definition.
     */
    public function content(): Content
    {
        return new Content(
            view: 'emails.thank_you_self_nominator',
        );
    }

    /**
     * Get the attachments for the message.
     *
     * @return array<int, \Illuminate\Mail\Mailables\Attachment>
     */
    public function attachments(): array
    {
        return [];
    }
}
php html laravel forms laravel-11
1个回答
0
投票

在 Livewire 组件中,您不使用请求对象,而是应该使用

$this
:

$data = [
            'first_name' => $this->first_name,
            'last_name' => $this->last_name,
            'nominee_name' => $this->nominee_name
        ];
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.