2

I have this class that takes care of emails.

public function mail($emails, $message)
    {

        Mail::queue('emails.notification', ['message' => $message], function($m) use ($emails) {
            $m->to($emails);
            $m->subject('Notification....');

        });
    }

the $massage parameter is called from the a this class,

private function report(Notification $notification, $resCode)
    {
        if(empty($resCode)){
            $resCode = "no response found";
        }

        $this->reporter->slack($notification->website_url . ':' . '  is down' . ' this is the status code!' . ' @- ' .$resCode,
             $notification->slack_channel);

        $this->reporter->mail($notification->email,$notification->website_url.' is down '. ' this is the status Code: '. $resCode);


    }

Now i want to display the message the message in the emails.notification.blade and i tried this way

@extends('layout')
@section('header')
@stop
@section('content')
        <h1>The Web site is down!</h1>
               {{ $message }}


@stop
@section('footer')
@stop


  [ErrorException]
  htmlspecialchars() expects parameter 1 to be string, object given

this is the exception that I got. anyone with a better suggestion?

3 Answers 3

3

In your controller, the variables are passed as an associative array to Mail::send():

$data = ['emailId' => $emailId, 'mailBody' => $mailBody];
    
Mail::send(
    'mail.emailForgotPassword',
    $data,
    function ($message) use ($data) {
        $message->from('xyz.com', 'abc');
        $message->to($data['emailId'])->subject('Your Subject');
    }
);

and in your Blade template, you can reference the variables by using {{$mailBody}} or {{$emailId}} .

Sign up to request clarification or add additional context in comments.

Comments

0

Based on Sending Mail, you can pass variable value in array form as second param.

Mail::send('templatepath', 'blade-variable', function($m) use($user){
     $m->from('[email protected]', 'From Label');
     $m->to('[email protected]', 'To Label')->subject('Subject');
});

Here blade-variable is a second parameter. You can replace you array value with this same.

Further, as from your placed error htmlspecialchars() expects parameter 1 to be string, object given. Means that $message variable is not the string. Check $message value and pass string like: ['message' => 'This is the message..!']

Hope this will clear your doubt!

2 Comments

that is the challenge that I have. Because the message is coming from an http request, it has website URL and status code. it is ab object. changing it into a string is the challenge.
Very simple..! Replace below code to you mail blade: <?php print('<pre style="color:red;">'); print_r($message); print('</pre>'); ?>
0

This Follow link

$info = array('firstname'=>'xyz','lastname'=>$lastname);
Mail::queue('emails.notification', ['message' => $info], function($m) use ($emails) {
        $m->to($emails);
        $m->subject('Notification....');

    });

view page print

{{ $message }}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.