Object of class Illuminate\Mail\Message could not be converted to string

Viewed 9536

I am using Laravel 5.5 trying to send email but getting error

Object of class Illuminate\Mail\Message could not be converted to string

here is my controller

public function contactreply($contact, Request $request){
    $reply = new Reply;
    $reply->subject = $request->subject;
    $reply->message = $request->message;
    $reply->email = $contact;
    $reply->save();
    $mail = Mail::to($contact)->send(new ContactReply($reply));
    return Redirect::back()->with('status', 'Email Sent Success');
}

here is my ContactReply.php

<?php

namespace App\Mail;

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

class ContactReply extends Mailable
{
    use Queueable, SerializesModels;

    protected $reply;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($reply)
    {
       $this->reply = $reply; //dd($reply) passing all value here
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('admin.contact.reply')
                    ->subject($this->reply->subject)
                     ->with([
                        'message' => $this->reply->message,
                    ]);
    }
}

my view file

<div>
  {!! Markdown::parse($message) !!}<!-- Using Markdown Package -->
</div>

I think I missing something because i did same on my old project and that is working fine.

3 Answers

i don't know why its a bug of laravel but $message is blacklisted for mail on view
when i tried {{ $message }} getting error and not sending the message
when i change $message to any name like {{ $content }} its working fine yeah its working fine now thanks for contribute all

Change the message input name in your contact controller

$input = $request->all();

    Contact::create($input);


     \Mail::send('contact.contactMail', array(
        'name' => $input['name'],
        'email' => $input['email'],
        'phone' => $input['phone'],
        'subject' => $input['subject'],
        'message' => $input['message'], // change in this line

to this -->

$input = $request->all();

    Contact::create($input);


     \Mail::send('contact.contactMail', array(
        'name' => $input['name'],
        'email' => $input['email'],
        'phone' => $input['phone'],
        'subject' => $input['subject'],
        'form_message' => $input['message'], //after change it will work
Related