-1

I am migrating from SwiftMailer to Symfony Mailer in my application.

How to migrate addPart method of SwiftMailer to Symfony Mailer? In my case the content type is text/plain

->addPart('Plain text content', 'text/plain');

using

  • swiftmailer 6.1
  • symfony mailer 4.4
yivi
  • 42,438
  • 18
  • 116
  • 138
Filip Kaszczyński
  • 139
  • 1
  • 2
  • 15
  • Wouldn't `$email->text("...")` do the job? https://symfony.com/doc/current/mailer.html#message-contents Or am I misunderstanding your question? – nikoshr Jan 12 '22 at 14:07
  • Yeah, in my case (plain text part) it seems to be exactly what I was looking for. Thank you. For some reason I overlooked this simple solution. – Filip Kaszczyński Jan 12 '22 at 14:14

3 Answers3

1

To set the plain text part of your email with Symfony Mailer, you can use

$email->text("...")

See https://symfony.com/doc/current/mailer.html#message-contents for a complete reference

nikoshr
  • 32,926
  • 33
  • 91
  • 105
1

You would just migrate it to

->text('Plain text content')

https://symfony.com/doc/current/mailer.html#message-contents

john Smith
  • 17,409
  • 11
  • 76
  • 117
1

You can use like this

$email->from($fromEmail)
->to($toEmail)
->html($html_content)  /// for html content
->text($text_content)  /// for text content 
->replyTo($email_info['reply_email'])
->subject($email_info['subject']);

hope this will help. Comment the line if you don't need html content or text content.

M Arfan
  • 4,384
  • 4
  • 29
  • 46