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

After update from laravel 5.5 to laravel 5.8 swiftmailers setBody method doesnt make any changes to body #28547

Closed
xUJYx opened this issue May 16, 2019 · 5 comments

Comments

@xUJYx
Copy link

xUJYx commented May 16, 2019

  • Laravel Version: 5.8.17
  • PHP Version: 7.3.5

Description:

After update laravel version from 5.5 to 5.8 when using swiftmailer raw method, mail sending starts to give error quoted_printable_encode() expects parameter 1 to be string, array given
swiftmail_error
If you provide some raw string data as first parameter - mail will be sent, BUT callback function will not make any changes to body with setBody method...
error_doesnt_overwrite

Steps To Reproduce:

Try to send e-mail with raw method using swiftmailer:
error_reproduce
`Mail::raw([], function ($message)

{
$message->to('some@email.test');
$message->from('from@my.mail', 'MyName');
$message->subject('Test email send');
$message->setBody('Some cute html body to send', 'text/html');
});`

How To Solve Problem:

In new versions of laravel 5.6+ had been moved call of call_user_func in /vendor/laravel/framework/src/Illuminate/Mail/Mailer.php in send($view, array $data = [], $callback = null) method...
swiftmailer_error_point
If you move call_user_func back as in previous laravel versions - problem will be solved and all will start work well.
swiftmail_error_solved

Thats it...

@xUJYx xUJYx changed the title After update from laravel 5.5 to laravel 5.8 swiftmailer raw mail send fails After update from laravel 5.5 to laravel 5.8 swiftmailer raw mail send fails with ERROR: "quoted_printable_encode() expects parameter 1 to be string, array given" May 16, 2019
@xUJYx xUJYx changed the title After update from laravel 5.5 to laravel 5.8 swiftmailer raw mail send fails with ERROR: "quoted_printable_encode() expects parameter 1 to be string, array given" After update from laravel 5.5 to laravel 5.8 swiftmailers setBody method doesnt make any changes to body May 16, 2019
@driesvints
Copy link
Member

This was the pr that made the change: #22995 to fix #22982

Since this is a case of wether it either breaks one or the other it's hard to consider this as a bug. I'd suggest that you either accommodate for this change or attempt another PR to change back to the previous behavior. But please try to provide a very thorough explanation why this should be a better way that the reasoning in #22995

@xUJYx
Copy link
Author

xUJYx commented May 16, 2019

This was the pr that made the change: #22995 to fix #22982

Since this is a case of wether it either breaks one or the other it's hard to consider this as a bug. I'd suggest that you either accommodate for this change or attempt another PR to change back to the previous behavior. But please try to provide a very thorough explanation why this should be a better way that the reasoning in #22995

I don't know how to very thorough explain this kind of issue. Alexander-- wants to modify encoder. He don`t care that his feature implementation ruins normal behavior of swiftmailer method. And can crash already built application on laravel version update...
I don't need to modify such stuff as Alexander-- wants. I just want that all the functionality which included in laravel packages and modules work as it must work. And his code make some methods dysfunctional. I just think, that making changes which ruins functionality - that is not normal.

Maybe it would be better to add some flag "if you want a priority in developer-supplied callbacks workaround"? Or add some examples of alternative methods for solving this kind of problem in documentation? I mean "how can I send row mails and what to do if I want to modify body in callback function"...

@driesvints
Copy link
Member

Hey @xUJYx. It's best that you post an issue in the ideas repo to get some feedback from other community members on this matter. Together you might figure out a good solution. Unfortunately I don't have the time myself to deep-dive into this at the moment.

@xUJYx
Copy link
Author

xUJYx commented May 16, 2019

@driesvints Done. Thanks...

@iget-master
Copy link

That PR #22995 also breaks things here:

In our case, we use the $this->withSwiftMessage(...) to modify the message body and add some attachments to the email. (we replace some cid references with urls and embed missing cid references files).

Our code is like

$this->withSwiftMessage(function (Swift_Message $message) {
    $body = $message->getBody();

    // Modify body, embed some files (searching for images with `src="cid:*` and replace with another cid and embed the file)

   $message->setBody($body);
}

This used to work on 5.5, and now we are migrating to latest version, but after 5.6 the callback order rearrange causes this issue.

I understand the reason of the rearrange, but I think that $this->withSwiftMessage() should be able to place a callback BEFORE and AFTER. Maybe, it can receive an optional parameter for placing it before.

Can @taylorotwell give a look here? I think this is an important issue.

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

No branches or pull requests

3 participants