Ad

I Have Problem But Can’t Find A Solution For 2 Days Laravel Email

- 1 answer

I don’t understand why it throws such an error. I call the variables from the controller and not the object.

Error:

Facade\Ignition\Exceptions\ViewException htmlspecialchars() expects parameter 1 to be string, object given (View: C:\OSPanel\domains\best.salon\resources\views\landing\mails-temlate.blade.php)

MAILcontroller:

    <?php

namespace App\Http\Controllers;
use Mail;
use Illuminate\Http\Request;

class MailController extends Controller
{

    public function store(Request $request){
        $client_name = $request->get('name');
        $email = $request->get('email');
        $message = $request->get('text');

        \Mail::send(['text' => 'landing.mails-temlate'], compact('client_name','email','message'),
            function ($message) use ($request){
                $message->to('[email protected]', 'Nuo Estik Puslapi Zinute')->subject('Nuo Estik Puslapi Zinute');
                $message->from('[email protected]', 'Nuo Estik Puslapi Zinute');
            });

        return view('landing.index', compact('client_name','email','message'));

    }
}

Mail template

CLIENT INFO:

Name: {{ $client_name }}
Email: {{ $email }}
-----------------------------------------
Message: {{ $message }}
Ad

Answer

Probably you should rename name of $message variable you use like so:

public function store(Request $request){
    $client_name = $request->get('name');
    $email = $request->get('email');
    $text = $request->get('text');

    \Mail::send(['text' => 'landing.mails-temlate'], compact('client_name','email','text'),
        function ($message) use ($request){
            $message->to('[email protected]', 'Nuo Estik Puslapi Zinute')->subject('Nuo Estik Puslapi Zinute');
            $message->from('[email protected]', 'Nuo Estik Puslapi Zinute');
        });

    return view('landing.index', compact('client_name','email','text'));

}

And in your view use $text variable instead of $message. I believe there is conflict here because you use $message as text you want to display but $message variable is also used inside closure and then it's object and not string.

Ad
source: stackoverflow.com
Ad