Skip to content

Instantly share code, notes, and snippets.

@vidux
Created January 10, 2021 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vidux/7936fcb4dff433190fd4612cfca023fa to your computer and use it in GitHub Desktop.
Save vidux/7936fcb4dff433190fd4612cfca023fa to your computer and use it in GitHub Desktop.
add sender to laravel Mailable build method
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class ExampleMail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($msg)
{
$this->msg = $msg;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$this->withSwiftMessage(function ($message) {
//to avoid message of 'behalf of' keep both sender and from details exactly as same
$message->setSender('contact@example.com','contact');
$message->setFrom('contact@example.com', 'contact');
});
return $this->subject('Example Email')->view('mails.example_mail_view');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment