Это видео недоступно.
Сожалеем об этом.

Symfony Mailer: How to Create Emails | Templated Email | Mail Catcher - [Symfony Workshop 2021]

Поделиться
HTML-код
  • Опубликовано: 27 окт 2020
  • ℹ In this recording I show you how to send email in Symfony using the Mailer class. Rather than getting bogged down in configuration, I also set up a mail catcher using Docker which allows you to imitate sending emails and view the email in your browser...pretty cool.
    🆓 Join garyclarke.tech for course DISCOUNTS and a FREE Docker + PHP course (worth $49)
    www.garyclarke.tech
    👇Follow me on Social Media:
    Twitter: / garyclarketech
    Linkedin: / garyclarketech
    💕Show support:
    www.paypal.com/donate/?hosted...

Комментарии • 30

  • @HerNameEscapesMe
    @HerNameEscapesMe 3 года назад +1

    You've got a good knack for delving deep enough into periphery topics that crop up to explain them, without either glossing over them or getting completely sidetracked. Love your work so far mate, has helped give me the nudge I needed to try and learn docker.
    Easy to follow, and you don't skip over things. Keep it up mate, will likely tune in for everything you release.

    • @GaryClarkeTech
      @GaryClarkeTech  3 года назад +1

      Cheers Emlyn, I appreciate your support and good luck with Docker...it's a pretty big subject but just learn as much as you're likely to use because you just end up forgetting the rest anyway...like I have!

  • @ramo012032
    @ramo012032 3 года назад

    Very nice tuto, great content, keep up the great work 💪💪💪

    • @GaryClarkeTech
      @GaryClarkeTech  3 года назад +1

      Thank you ramo..I appreciate it. Plenty more to come!

  • @vhur8836
    @vhur8836 2 года назад

    Gary To many known a random guy found on yt but to me he taught me how to use smfony i love Gary Thankl u Gary

  • @sergemaminiaina252
    @sergemaminiaina252 3 года назад

    Thank you bro ^-^

  • @thijsdew1988
    @thijsdew1988 2 года назад

    Hi Gary, thank you for the content. Would these settings work on a production env as well? Or do i have to change some settings if i'm going on a live server?

    • @GaryClarkeTech
      @GaryClarkeTech  2 года назад +1

      Yes..you'd need to set it up for whichever 3rd party transport you use...
      symfony.com/doc/current/mailer.html#using-a-3rd-party-transport

  • @Trixxro
    @Trixxro 3 года назад

    Awesome tutorial! What editor are you using?

    • @GaryClarkeTech
      @GaryClarkeTech  3 года назад +1

      Thanks..I appreciate it! Using PHPStorm with the Symfony Support plugin enabled.

    • @Trixxro
      @Trixxro 3 года назад +1

      Ty 👏

  • @cprn.
    @cprn. 3 года назад

    Do you happen to know how to make `Email` properly build the message with some attachments inlined via `cid` in HTML content (in `related` part of the body) and some as actual attachments (in `mixed` part)? I can't seem to find an example other than working with raw `Message` object and everything I tried so far builds a message with either attached files or inline images but not both.

    • @GaryClarkeTech
      @GaryClarkeTech  3 года назад

      Hmm..good question. I'll investigate.

    • @cprn.
      @cprn. 3 года назад

      @@GaryClarkeTech I kind of figured it out. Kind of. Don't know if RUclips comment will show code correctly but here it goes, typed on a phone:
      $email->html(""); # lands in `related`
      $email->embed($file['content'], $file['name'], $file['mimeType']); # lands in `related`
      $email->attach($file2['content'], $file2['name'], $file2['mimeType']); # lands in `mixed`
      File names have to be unique. It doesn't work in CSS, e.g. `background-image: url(cid:{$file['name']})`, and even if it would, Thunderbird doesn't render it - there's a 15 years old bug still active. It still doesn't work in Thunderbird sometimes. Don't know why yet.
      The reason I even asked is because I had attachment as `DataPart` like so:
      $embedded = new DataPart($file['content'], $file['name'], $file['mimeType']);
      $embedded->setInline();
      $email->attachPart($embedded, $embedded->getContentId());
      In this case `$file` Lands in `mixed` with disposition `inline` - it works in e.g. Gmail but Thunderbird requires it to be in `related` alongside `$html` to render properly as embedded image.

    • @GaryClarkeTech
      @GaryClarkeTech  3 года назад +1

      @@cprn. Impressive that you did that on a phone! 🙌

  • @anas1634
    @anas1634 3 года назад

    what about .env file? what is the value of MAILER_DSN?

    • @GaryClarkeTech
      @GaryClarkeTech  3 года назад

      That comes from docker-compose in this scenario, not the .env file
      Here's an explanation:
      symfony.com/doc/current/setup/symfony_server.html#docker-integration

  • @parijke
    @parijke 3 года назад

    Gary, if I want something to be templated in the database to assist for multiple languages, how would you approach that?
    i.e. I want to have this in a text field in my MailTemplate enity, something like:
    Dear {{user.Fullname }}
    Here's your invoice number {{invoice.number}}
    and render it using the TemplatedEmail() function...

    • @GaryClarkeTech
      @GaryClarkeTech  3 года назад

      Hey Paul...it's not something I've tried but I'd probably avoid putting it in the DB, keep everything in email template files and use the Symfony translation service.
      I'll have a look at the translator in a future recording cos I'd like to get more familiar with it...I can try to recreate what you describe.

    • @parijke
      @parijke 3 года назад

      @@GaryClarkeTech thanks Gary. But in this case, the users can create email templates themselves. I.e. this is a boking system, so the owner of a property can create an email template as a welcome message. I don't see how to do that without creating the templates in the database?

    • @GaryClarkeTech
      @GaryClarkeTech  3 года назад

      @@parijke Ah right...I get you now. If they are all gonna be allowed to create something completely custom, then you can store the body as text in the DB and have placeholders which can be parsed and replaced with values such as names etc using string replace functions. Maybe do the find and replace first before passing it into a template as a $body variable. In fact, if you're using entities, you could build it into the email body getter function. Show me what you come up with and we can figure something out.

    • @parijke
      @parijke 3 года назад

      @@GaryClarkeTech ❤

    • @parijke
      @parijke 3 года назад

      Got it working it was even easier that I thought. I share a raw version, maybe you've got some ideas to improve if you have the time and are in to it

  • @ApoRekt
    @ApoRekt 2 года назад

    does this work for symfony 6?

    • @ApoRekt
      @ApoRekt 2 года назад

      nope

    • @garetts8156
      @garetts8156 2 года назад +1

      @@ApoRekt just finished, everything works on Symfony 6 and PHP 8.1