Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Mailer] string variable named 'email' becomes WrappedTemplatedEmail object #33310

Closed
@ryckblick

Description

@ryckblick

Symfony version(s) affected: 4.3.3

Description
I'm trying to pass a variable named 'email' to Twig via ->context(). Causing preg_match() in Generator/UrlGenerator.php:179 to fail with "Warning: preg_match() expects parameter 2 to be string, object given"
Debugging the email var shows, that it somehow became a WrappedTemplatedEmail object.

How to reproduce

$message = (new TemplatedEmail())
                ->subject('...')
                ->from('...')
                ->to($user->getEmail())
                ->textTemplate('...')
                ->context([
                    'email' => $user->getEmail(),
                    'identifier' => urlencode($identifier),
                ])

            $mailer->send($message);

Possible Solution
Renaming the variable 'email' to 'mail' fixes the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions