i can send mail with laravel as below, but what i want is this; I want to make the subject part dynamic, how can I achieve this?
$sendAdmin['sendAdmin'] = $data;
Mail::to('[email protected]')->send(new \App\Mail\ContactMail($sendAdmin));
class ContactMail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public $details = [];
public function __construct($details)
{
$this->details = $details;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->subject('Hello Mail')->view('email.contactform');
}
}
CodePudding user response:
Assuming that the subject comes from your $details
array, it's pretty simple:
public function build()
{
return $this->subject($this->details['subject'])->view('email.contactform');
}