Laravel Email Sending With File/Image Attachment Using Mail Facades 👌 Send Email Using Laravel.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys if you like my awesome gaming videos my programming and web development courses my editing courses and editing videos and my tech talks and tech guidance then you can consider subscribing to my channel and click on this bell icon to stay connected with me all the time hello everyone welcome to my channel so in this video as you can see i'm talking about larval emails i hope you are really following my laravel course where i've talked about a lot of things about larpel if you didn't check it out obviously check my previous videos where i talked a lot of amazing stuffs about larval and as you know the all the larval tutorials that i make for you is covering the basic and the little bit of intermediate section where most of the people get stuck and very important to understand so in this video i'm talking about the larval email uh facet as you can see we are gonna use the email facet or mail facet for laravel which really helps us to send email to particular user so first step we need to follow is laravel environment file and you need to set up some configuration then we are going to create php artisan config clearly to clear all of our config because when you write something in the environment you need to clear the config third step is to make our controller and which is we're going to call mail controller and we're going to add some features to send okay we're going to learn three type of mail which is text mail email mail and email attachment mail three types of mails and routes and all other controllers we're gonna add all those functionalities that we created so these are the main five steps that we need to follow to send email but before that we need to make sure that disabled two-step authentication on your google account security services so as you can see in the video you can easily turn on and turn off your two-step authentication in google account for this purpose if you want to test it live and send all of this thing i'm gonna show you in the video that how can you see that and just get confirmed that how it is working and i'm gonna show you with using the real google account as you can see and you need to also allow less secure apps on your google account so so that we can send email directly to your google account or gmail account so first we need to create our application go to our terminal and here i'm gonna write laravel new email sender project so our new project name is email sender project okay so it will take some time to create and by this time just chill so as you can see our level application is created now enough to get out of this thing so we have email sender project okay so do code email center project and just go to the new terminal so our development server is running if we go into this link as you can see our development server is running properly environment folder this is the very important thing and this is the part um where you're gonna learn all of those things and put all of your credentials for the environment variables so this is the place where you put all of this information like database connection database name all of those things and here the most important part when i zoom in you can see very clearly we have some information mail mailer mail mailer is actually here as mtp okay so this is the service we're gonna use and our host is smtp.gmail.com okay so smtp.gmail.com this is our host that will send mail from one user to another user okay and our port is 587 587 you can google it and learn what is the port number for smtp services to send mail okay especially this is work for the google account gmail as you can see and this port is 587 and this is the mail username mail username is suppose my name is greatadeeb or adeb you can see adid gmail.com so this is actually a mail the full username but we need only the thing that is before this add sign so you need to delete everything so this is just a normal mail username okay then you need to have a password so this is a very dangerous thing and this is a very important that you don't write it on the especially in the video tutorial that i'm making this you cannot write password like this way okay so this is very secret thing and this is the same password that you're gonna use for your google account password and this is the same password that you're gonna put here okay suppose it is one two three four then it is one two three fours if it is something else it is something else just put it and the mail encryption point is tls normally this is the standard tls encryption for the mail this is very important so these are some environmental uh configuration that you just set up first is the mail driver which is smtp then we have the host which is smtp.gmail.com and its port is 587 and you gmail username and his own secret password is address suppose mail from address when you you need to send some email from one user to another user suppose this is the user who sent to the mail and some and you need to write some other mail who will be getting that email so this is the mail who is going to send the mail and this is just a simple example suppose in case of mine it should be like this at example.com in case of yours it is suppose xyz example.com because this is the demo project and you guys all know how to put all of your email here you are a complete developer okay so if this is the password that you're gonna put suppose i just keep it one two three four here for the development or the demo purpose so this is the environmental setup very important and i need to get out of your shell okay and you just need to write php artisan config clear this is important config you need to clear the configuration because you just changes the some important variables in the environment variables okay so this is very very important the second step as you can see we have laravel environment file main configuration setup is done then our cache clearing is done and then to create a controller let me create a controller for you so php artisan make me a controller and its name is mail controller so our controller is created if we go to app click on http go to controllers we have main controllers um here i'm going to put something called use mail okay so use illuminate support facet mail so this is the face that we're gonna use to send our mail so first one is the very basic image very basic image so far that are gonna write some functionalities public function send basic email again so this is the functionality name and here you need to write um and in the body we're gonna add some data suppose and this should be in error format you can put in many format but i like the error format more so suppose the name and the name is and this is the name that i'm gonna send to suppose i am great adid and i'm sending this mail to gadjiadi okay so this is very important and this will hold all the information like this name in associative array in the data variable sensor mail me so mail and here i'm to use send functionality as it will takes three parameters first one is view then data and contact functions and here i'm gonna use text as mail and to send this email as text format okay so there are three format one is html format one is text format and this is the text format and it will be mail okay and then we need to put some data variable which one or which variable or which user i need to pass this mail to and this is the name and this holds all in the data variable okay so the name of the person that whom i'm sending this email to and this is holding inside the variable data and this is the thing then to pass in the parameter in the mail dot send method okay then we have view is done which is text as email and then we have the data i already passed it and into callback function and in the callback function you need to use a function and function here i'm going to use message so in the message everything is done here first message and message we need to send to whom i'm gonna sending this message suppose i'm gonna send this message to pqr at gmail.com don't use it in your main project because this is a simple uh demo to show you use your own personal gmail account and use your gmail and you can put another information to gadget because this is the person you are sending to okay you can attach this and you can attach one more functionality which is subject because each email should have a subject which looks very professional and this is laravel um youtube tutorial on email so this is the subject of youtube tutorial on email then what you can write message and here you can write from because from is important who is sending the email and two is to whom you are sending the email okay and the subject should be like xyz is sending the email at gmail.com make sure it is gmail because you need to use smtp.gmail.com is your main host so you need to use gmail account on that or google account and you can also put your name here who is sending the mail suppose great i will be sending the mail okay and this is the person who is sending the mail and two is to whom you are sending the mail okay very important and yeah we're gonna show the simple message as as it is like that so after i did all of this you need to echo something uh email is sent or email is sent perfect you can add one more function uh for that i'm gonna copy everything and this function is for attachment attachment okay you can use some more attachment and send a touch email okay suppose this function this name is send attach email if you want to send any image or text file to it okay so same everything everything is same just here or email attach this subject should be email attachment okay you are sending to this person from this person and also you can add one more parameter here which is a touch you can attach something and how can we attach something suppose for that you need to have some data okay you need to have some data in your um public folder you need to create one more folder called uploads and in the uploads folder you can put to two images suppose we have images here as you can see this is the images into drag and drop here as you can see and then we have valentine okay so the valentine day and iphone 13 product png all of them are png make sure that you write it perfectly and you need to go to its directory and how can you go to its directory so for that you need to go to your main project level workspace we have our email center project to public uploads okay so this is the root directory web development framework then you to google laravel verbal workspace then your project and public uploads folder just copy this directory because in this directory we have these images so this directory is very important and here you need to pass all of those things as you can see in the uploads folder we have two images which is iphone 13 pro and valentine so first one is your valentine underscore day dot png simple and you just need to copy this and send one more file which is iphone 13 pro.png so just write it perfectly otherwise it will never gonna work iphone13 pro.png and valentine underscore uh day dot png so this is the thing that you need to attach on those two images you can attach some files as text format for that you need to write something like txt or pdf for pdf okay so as it is an image i just write it p and g that works really well and they need to write from which i'm sending then we have one more format and which is almost like this one let me copy this thing and paste it here this is just a basic html email it will show only the html property like h1 and ptag after you send the email okay so basic um html email suppose sent html email this is the function name and you need to just change here so this is the part we need to change here you need to write as mail send the mail as mail and it will just show all the html format okay and if you write as text mail then it will show all the text and html tags all of those things okay in the mail but if you do just write it like mail like this it will be very plain and easy for you to understand so you can check it out you we have three format which is html email then we have attachment that we can attach something images pdfs on different kind of files and other things are very similar to whom we are sending and from who from which people we're gonna sending and to whom we are sending very simple all of the things are pretty similar then we can also change it to for the attachment we need to change it to mail very simple we can change it to make this is for the simple um mail format which is directly converted into html and then we have attach format where does something and then we have simple mail as text so we need to go to our routes folder and the dashboard web.php and we're just gonna delete everything just keep it simple route and get okay and here to write some functionalities and we need to use mail controller okay http controller main controller that we created and you to use this function it is called basic basic email just copy this thing and in the mail controller mail controller class you can use this functionalities okay very simple and you can copy this thing and paste it and this is for the basic html email and this is for send html email if you want to send it in html format and then we have attachment attach mail format and here you're gonna use this functionality send attach email just keep it similar send attach email send at html and then we have the html and this is for this sent basic send basic and then we have send html email send html so we have three format okay web server so for that is just php artisan optimized to optimize everything like it will create our cache all of those things properly and route cache all of this important so after we just gonna run php artisan [Music] server random server so one more thing we forgot which is very important and for that you need to go to resources resources and views you need to create one more file called mail.php and here you need to write something and html page email sender and here you can put something called hi it will hold something called our name okay hi how are you okay and here you write p tag i send an email to you okay so this is the person where you just send them email to so if you go to the mail controller and here as you can see in the data variable i stored a name called gadget this is the person i'm sending this mail to so this is the name array attribute and this is the attribute that we can set here so when the image is sent you can see this blade mail.black.php page very simple and this is the name that hold like gajiadi okay that this name hold it so it will say hi how are you i sent an email to you okay very simple and then when you start and run the server now as you can see every single thing work really fine without any single hiccups or any single issues and i think you guys really understand how this is working really fine as you can see we have all the images and we have all the normal html tags and html thing that we that shows hi how are you i'm sending an email to you so i think from now on you guys really are really smart enough to understand how you can send some mail to your clients to your personal users to all of those things very easily very simply even you can send the authenticated user mail so i think the most of the thing i showed here in it really works really well if you follow and it is able to step on google account and allow less secure apps so these are all the simple and basic stuff they need to do to send email to any customer or the client so i hope you learned a lot of things about laravel image center and email facet or mail facet and how you can add subject however you can add email how you can add attachment to your image pdf file image file or any text file very easily very simply so that's all for today i hope you learned a lot of things and subscribe and share as much as possible so that i can give you much better content in the near future so the next video i'm gonna talk about networking which is really awesome videos and i hope you will understand a lot of amazing stuff from that video so thanks for watching i will become the next video with more awesome content till then take care bye
Info
Channel: Great Adib
Views: 7,409
Rating: undefined out of 5
Keywords: laravel, laravel 8, laravel tutorial, laravel 8 tutorial, laravel mail send, laravel send email with attachment, laravel html email send, laravel text email send, send email in laravel, how to send email in laravel, laravel 8 tutorial for beginners
Id: 3rj4NXKpD1k
Channel Id: undefined
Length: 19min 6sec (1146 seconds)
Published: Sun Feb 20 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.