How to send mail without including html in laravel?

Viewed 1770

I am trying to send a mail through Laravel. here's my code:

sendMailable.php file inside mail folder

<?php

namespace App\Mail;

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

class SendMailable 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->view('view.name');
    }
}

my controller code is :

$data= ['name'=>'sakal de boss'];
            Mail::send(['text'=>'mail'],$data, function($message){
            $message->to($to, 'sakal')->subject('ami mail korsi');
            $message->from($from,'sakal');
        });

        echo 'hey';
         }

view page:

<div>
    Hi, This is : {{ $name }}
</div>

there is no other tags in my view page but still i am getting html tags in mail.

here is mail which i am getting.

Mail output:

enter image description here

3 Answers

Try this in your .blade.php file: (View)

{!! $name !!}

Instead of this : (This will render your HTML)

{{ $name }}

use {!! $name !!} OR <?= $name ?> instead of {{ $name }}

OR

Mail::send(['html.view', 'text.view'], $data, $callback);

your first parameter 'text' will concider as plain mail so Try below one

Mail::send('email view name',$data, function($message){
            $message->to($to, 'sakal')->subject('ami mail korsi');
            $message->from($from,'sakal');
        });

or

Mail::send( ['html' => 'email view name'], $data, function($message){
                $message->to($to, 'sakal')->subject('ami mail korsi');
                $message->from($from,'sakal');
            });
Related