Bug #89379

Emails sending doesn't work using MailMessage

Added by Pixelant Developer 2 months ago. Updated about 2 months ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2019-10-09
Due date:
% Done:

0%

TYPO3 Version:
10
PHP Version:
7.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

Get en exception when trying to send an email in TYPO3 v10.1 and symfony/mailer v4.3.5

(1/1) Symfony\Component\Mime\Exception\InvalidArgumentException
An address can be an instance of Address or a string ("array") given).

in /var/www/typo3_10_dev/vendor/symfony/mime/Address.php line 81

Code example:

$mail = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);

        $mail->setSubject('Your subject');
        $mail->setFrom(array('john@doe.com' => 'John Doe'));
        $mail->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'));
        $mail->setBody('Here is the message itself');
        $mail->send();

Related issues

Related to TYPO3 Core - Bug #89083: MailMessage setFrom and setTo are throwing exceptions Resolved 2019-09-04

History

#1 Updated by Georg Ringer 2 months ago

  • Status changed from New to Needs Feedback

can you check if solved with #89083? patch is pending at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61908

#2 Updated by Georg Ringer 2 months ago

  • Related to Bug #89083: MailMessage setFrom and setTo are throwing exceptions added

#3 Updated by Pixelant Developer 2 months ago

Georg Ringer wrote:

can you check if solved with #89083? patch is pending at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61908

Patch fixes an error when use setFrom and setTo.
But setBody doesn't accept string.

// This cause exception 
$mail->setBody('Here is the message itself');
(1/1) TypeError
Argument 1 passed to Symfony\Component\Mime\Message::setBody() must be an instance of Symfony\Component\Mime\Part\AbstractPart or null, string given

#4 Updated by Georg Ringer 2 months ago

yes because you need to use

->html()
->text()

instead. the API changed in 10.0

#5 Updated by Pixelant Developer 2 months ago

Georg Ringer wrote:

yes because you need to use
[...]

instead. the API changed in 10.0

It's working

#6 Updated by Riccardo De Contardi 2 months ago

@Pixelant Developer thank you for your quick reply; is there something that should be done or the issue can be considered solved?

Thanks.

#7 Updated by Pixelant Developer 2 months ago

Riccardo De Contardi wrote:

@Pixelant Developer thank you for your quick reply; is there something that should be done or the issue can be considered solved?

Thanks.

Solved =)

#8 Updated by Riccardo De Contardi about 2 months ago

  • Status changed from Needs Feedback to Closed

Thank you; I close this issue as solved - please reopen or ping me if you think that this is the wrong decision.

Also available in: Atom PDF