Creating, Configuring & Sending the Email Object - Symfony Mailer- Love Sending Emails Again

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
time to send an email after a user registers for a new account we should probably send them a welcome email the controller for this page lives at sourcecontroller securitycontroller.php the register method this is a very traditional controller it creates a symfony form processes it saves a new user object to the database and ultimately redirects when it finishes let's send an email right here right after the user is saved but before the redirect how it's gorgeous start with email equals new email the one from the mime namespace actually this is a good moment to mention that when we talk about the mailer component in symfony we're actually talking about two components mailer and mime the mime component is all about creating and configuring the email itself and mailer is all about sending that email but mostly that's not too important just don't be surprised when you're using objects from this mime namespace i've put the new email object in parentheses on purpose it allows us to immediately chain off of this to configure the message pretty much all the methods on the email class are delightfully boring and familiar let's set the from address to how about alienmailer example.com v2 to the address of the user that just registered so user arrow get email and this email needs a snazzy subject welcome to the space bar pure poetry finally our email needs content if you've sent emails before then you might know that an email can have text content html content or both we'll talk about html content soon but for now let's set the text content of the email too nice to meet you and then open curly close curly user arrow get first name and of course a heart emoji there are a bunch more methods on this class like cc add cc bcc and more but most of these are dead easy to understand and because it's such a simple class you can look inside to see what else is possible like reply to we'll talk about many of these like attaching files later so that's it that's what it looks like to create an email i hope this wowed you and disappointed you in its simplicity all at the same time okay so now how do we send this email as soon as we installed the mailer component symfony configured a new mailer service for us that we can auto wire by using surprise the mailer interface type hint let's add that as one of the arguments to our controller method mailer interface mailer and what methods does this object have on it oh just one mailer arrow send and pass this email i love how this looks but will it work we haven't actually configured how emails should be sent but ah let's just see what happens move over and register first name fox last name molder in case you're wondering email the truth is out there at example.com any password agree to the terms that we definitely read and register ah error environment variable not found mailer underscore dsn okay fine to actually deliver emails we need to add some configuration via this environment variable let's talk about that next including some awesome options for debugging emails while you're developing
Info
Channel: Addis Times - አድስ ታይምስ
Views: 1,310
Rating: undefined out of 5
Keywords: Addis Times- አድስ ታይምስ, Addis Times, seid mohammed, Science and Technlogy, programming, ICT, How to, IT, PHP, Web developemnt, software, symfony 5, symfony, symfony framework, symfony php, symfony tutorial, up and running with symfony, symphony 5 symfony tutorial for beginners, symfony course, symphony, symphony tutorial, php framework, php, php tutoria
Id: HzMKhVkzfUY
Channel Id: undefined
Length: 4min 14sec (254 seconds)
Published: Sun Feb 27 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.