Created
January 10, 2021 15:22
-
-
Save vidux/ae4f66abf017dff40401aae7a780694a to your computer and use it in GitHub Desktop.
Laravel Email event listener for add / modify sender
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 | |
//blog.vidu.dev | |
namespace App\Listeners; | |
use Illuminate\Mail\Events\MessageSending; | |
use Illuminate\Queue\InteractsWithQueue; | |
use Illuminate\Contracts\Queue\ShouldQueue; | |
class EmailEvent | |
{ | |
/** | |
* Create the event listener. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
// | |
} | |
/** | |
* Handle the event. | |
* | |
* @param MessageSending $event | |
* @return void | |
*/ | |
public function handle(MessageSending $event) | |
{ | |
//check get is from is set | |
if (!empty($event->message->getFrom())) { | |
//get current from array | |
$from = $event->message->getFrom(); | |
//check sender already set by a in function code | |
if (empty($event->message->getSender())) { | |
//if empty set sender data as from data | |
$event->message->setSender($from); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment