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

Argument #2 ($value) must be of type string, null given #38

Open
ndijkstra opened this issue Sep 6, 2023 · 9 comments
Open

Argument #2 ($value) must be of type string, null given #38

ndijkstra opened this issue Sep 6, 2023 · 9 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@ndijkstra
Copy link

I'm getting this error from time to time:

Symfony\Component\Mime\Header\Headers::addTextHeader(): Argument #2 ($value) must be of type string, null given, called in /vendor/symfony/mime/Header/Headers.php on line 152

This is triggered by vendor/resend/resend-laravel/src/Transport/ResendTransportFactory.php: 66

@ndijkstra ndijkstra changed the title Header, Argument #2 ($value) must be of type string, null given Argument #2 ($value) must be of type string, null given Sep 6, 2023
@jayanratna
Copy link
Collaborator

jayanratna commented Sep 6, 2023

I'll take a look at the issue. Is it possible for you to provide the code for your Mailable class or API request payload if you're using the Facade.

@ndijkstra
Copy link
Author

ndijkstra commented Sep 6, 2023

Thanks for your swift reply! Is this enough for you?

$mailer->send('emails.empty', [
    'msg'      => $this->data['message'],
    'subject'  => $this->data['subject'],
    'fromName' => $this->data['fromName'],
    'logo'     => ($this->data['logo'] ?? null) !== null ? Storage::url($this->data['logo']) : null,
    'locale'   => $this->data['locale'] ?? null,
], function ($m) {
    $m->from($this->data['fromEmail'], $this->data['fromName']);

    $email = explode(',', $this->data['email']);

    $m->to(trim($email[0]), $this->data['name'])->subject($this->data['subject']);

    if (isset($this->data['replyToEmail']) && $this->data['replyToEmail']) {
        $m->replyTo($this->data['replyToEmail'], $this->data['replyToName'] ?? null);
    }
});

@jayanratna
Copy link
Collaborator

This is perfect thanks! Give me a day or two while I look into this for you. I think you might also be able to refactor this code to be more readable. I'll update you soon.

@jayanratna
Copy link
Collaborator

@ndijkstra I wasn't able to reproduce the error on my end. Could you please send through some dummy data for $this->data that fails?

@ndijkstra
Copy link
Author

ndijkstra commented Sep 7, 2023

I see there are some 422 errors visible in the Resend logs. It should have thrown that exception, instead of this error about null passing in the header.

Response body:

{
    "statusCode": 422,
    "name": "invalid_parameter",
    "message": "Invalid `from` field. The email address needs to follow the `[email protected]` or `Name <[email protected]>` format"
}

@jayanratna
Copy link
Collaborator

jayanratna commented Sep 7, 2023

You're absolutely right about the error being returned as an exception. I actually already have a fix for that waiting for review: resend/resend-php#35

@bukinoshita could you please review the above PR as soon as you can. ❤️

@jayanratna jayanratna added bug Something isn't working good first issue Good for newcomers labels Sep 7, 2023
@jayanratna jayanratna self-assigned this Sep 7, 2023
@jayanratna
Copy link
Collaborator

@ndijkstra could you please try reinstall resend/resend-laravel and ensure that resend/resend-php 0.7.2 is installed? This will fix the invalid_parameter exception issue.

@wassim
Copy link

wassim commented Jan 17, 2025

@jayanratna This still happening with 0.14.0

@jayanratna jayanratna reopened this Jan 17, 2025
@jayanratna
Copy link
Collaborator

Thanks for reporting this @wassim. I'll investigate and get back to you ASAP. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants