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.
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
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
$message variable is not available in markdown messages.
Source: https://laravel.com/docs/5.6/mail#writing-mailables
I think this is because the $message represents the Illuminate\Mail\Mailable instance itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With