Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mail::alwaysTo not working for synced mails #53614

Open
vatsake opened this issue Nov 21, 2024 · 1 comment
Open

Mail::alwaysTo not working for synced mails #53614

vatsake opened this issue Nov 21, 2024 · 1 comment

Comments

@vatsake
Copy link

vatsake commented Nov 21, 2024

Laravel Version

11.24.1

PHP Version

8.3.6

Database Driver & Version

No response

Description

In my AppServiceProvider boot method I have

if (!App::isProduction()) {
    Mail::alwaysTo('[email protected]');
}

I have a job that sends an email.

class SendEmail implements ShouldQueue
{
    use Dispatchable;
    use InteractsWithQueue;
    use Queueable;
    use SerializesModels;

    /**
     * Create a new job instance.
     */
    public function __construct(public array|string $from, public string $subject = '', public string|array $to = [], public array|string $cc = [], public array|string $bcc = [], public string $content = '')
    {
        //
    }

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        Mail::html($this->content, function (Message $message) {
            $message->to($this->to)
                ->bcc($this->bcc)
                ->cc($this->cc)
                ->subject($this->subject);
            if (is_array($this->from)) {
                $message->from(...$this->from);
            } else {
                $message->from($this->from);
            }
        });
    }
}

Steps To Reproduce

If sending email like this:
dispatch(new SendEmail(subject: 'test', to: '[email protected]', content: 'test'));
The email will be sent to alwaysTo address.

If dispatching like this:
dispatch_sync(new SendEmail(subject: 'test', to: '[email protected]', content: 'test'));
The email will NOT be sent to alwaysTo address...

BTW I'm using octane, so it might be 1 reason why it doesn't work.

Copy link

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants