Created
January 10, 2021 15:03
-
-
Save vidux/7936fcb4dff433190fd4612cfca023fa to your computer and use it in GitHub Desktop.
add sender to laravel Mailable build method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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