I have used markdown mailables which is a new feature in laravel 5.4. I have successfully implemented a mail sender. It seems, the subject of the mail is named as the name of the mailable
class. I need to change the subject of the mail and it's hard to find any resources regarding this.
Asked
Active
Viewed 3.2k times
21

Shashika
- 1,606
- 6
- 28
- 47
-
Please add some code. We know what is markdown mails in laravel. – Pankit Gami Apr 17 '17 at 06:12
-
This appears to be an issue with the ShouldQueue implementation, i am having the same issue – Mfoo Nov 26 '18 at 13:25
3 Answers
53
There is subject method in laravel mailables.
All of a mailable class' configuration is done in the build method. Within this method, you may call various methods such as from, subject, view, and attach to configure the email's presentation and delivery. : https://laravel.com/docs/5.4/mail#writing-mailables
You can achieve this like this :
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from('example@example.com')
->subject('Your Subject')
->markdown('emails.orders.shipped');
}
You may need to execute php artisan view:clear
after modifying your class.

Community
- 1
- 1

Pankit Gami
- 2,523
- 11
- 19
4
If the email subject is the same for all emails then just overload the $subject parameter in your extended Mailable class.
/**
* The subject of the message.
*
* @var string
*/
public $subject;

rStyles
- 111
- 6
0
complete code (tested)
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Mail;
class ContactController extends Controller {
public function sendContactMail(Request $request) {
$this->validate($request, [
'name' => 'required',
'email' => 'required|email',
'subject' => 'required',
'user_message' => 'required'
]);
Mail::send('contact_email',
array(
'name' => $request->get('name'),
'email' => $request->get('email'),
'subject' => $request->get('subject'),
'user_message' => $request->get('user_message'),
), function($message) use ($request)
{
$message->from($request->email );
$message->subject("Your Subject");
$message->to('email to');
});
return back()->with('success', 'Your message was sent successfully');
}
}

Deepak Yadav
- 227
- 3
- 4