Это видео недоступно.
Сожалеем об этом.
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...
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.
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!
Very nice tuto, great content, keep up the great work 💪💪💪
Thank you ramo..I appreciate it. Plenty more to come!
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
Welcome!
Thank you bro ^-^
You're welcome Serge
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?
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
Awesome tutorial! What editor are you using?
Thanks..I appreciate it! Using PHPStorm with the Symfony Support plugin enabled.
Ty 👏
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.
Hmm..good question. I'll investigate.
@@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.
@@cprn. Impressive that you did that on a phone! 🙌
what about .env file? what is the value of MAILER_DSN?
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
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...
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.
@@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?
@@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.
@@GaryClarkeTech ❤
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
does this work for symfony 6?
nope
@@ApoRekt just finished, everything works on Symfony 6 and PHP 8.1