Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
Laravel 5.4 change the subject of markdown mail

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.

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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.

about 4 years ago · Santiago Trujillo Report

0

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;
about 4 years ago · Santiago Trujillo Report

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');
    
        }
    }
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!