Laravel email Templates

Viewed 102

Hello I want to send e-mails rendered from templates that can be created / modifed by admin from a form (with placeholders).As in the example below and I want to send it to 100 users at the same time, I don't know how to do it, can you help?

Hi { { name } }, 

email: {{email } }

phone: { { phone } }

my controllers:

    public function mailSend(Uye $uye, IcerikSablon $icerikSablon){
    $dil_id=$uye->ulke->dil_id;
    $icerikSablon->load(['translation'=>function($q)use ($dil_id){
        $q->where('dil_id',$dil_id);
    }]);
    $icerik_sablon_icerik=$icerikSablon->translation->icerik;


    $uye_name=$uye->name;
    $uye_phone=$uye->phone;
    $uye_mail=$uye->email;
    $icerik_sablon_icerik=  str_replace('{{name}}', $uye_name, $icerik_sablon_icerik;
    $icerik_sablon_icerik=str_replace('{{phone}}', $uye_phone, $icerik_sablon_icerik);
    $icerik_sablon_icerik=str_replace('{{email}}', $uye_mail, $icerik_sablon_icerik;

    


}
1 Answers

You should really look into the documentation for mailables and notifications for Laravel, it seems you are missing some basic setup. https://laravel.com/docs/8.x/mail

From the docs: php artisan make:mail OrderShipped --markdown=emails.orders.shipped

Then pass in the parameters you want to dynamically have in the OrdersShipped class constructor, and assign them as variables in your class. You can then reference these variables within your blade template.

For example:

<?php

namespace App\Mail\Users;

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

class OrdersShipped extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * someVar
     *
     * @var $someVar;
     */
    protected $someVar;

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

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->from('test@test.com')
            ->subject('Password Reset Request')

            // Pass your vars in here using `with`

            ->with([
                'someVar' => $this->someVar,
            ])
            ->view('emails.orders.shipped');
    }
}

In emails.order.shipped blade you will be able to reference {{ someVar }}

Related