Best way to Send an Email with Laravel

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends in this video tutorial we are going to learn how to send an email from Louisville application sending of an email is a common feature of any web application this is mainly used for connect with customer for sending their feedback or query but in Louisville cent of an email is not much easier than send an email from simple PHP script or from codeigniter application in Louisville we will mailable for send an email in Louisville there are a number of other email class available but here we will use mailable for send an email in Louisville this is our Louisville application working folder and in this first we want to make one controller for handle HTTP requests for this we have go to command prompt in which we have already run composure command and we have come into Louisville working folder so for create controller we have write this command this command has make send email controller under app folder and under this we have to open HTTP folder and under this HTTP folder we have to open controller folder and here we can see send email controller file under this file first we have make index function this is the root function of this controller under this function we have right returns statement with view method and under this method we have writes and email view file which we have already created under resources' slash views folder in send email dot blade dot PHP view file we have already imported JavaScript library jQuery and bootstrap library under this file we have to make one form for send an email so here we have write form with attribute method is equal to post and action is equal to URL function and under this we have rights and email controller / send function so when we have click on Form submit button then it will send request to send method of send email controller under this function first we have right CSRF field function this function will protect your application from cross-site request forgery attacks first we have to make text box for enter name details so here we have write input type is equal to text name is equal name under this field user can enter their name details after this we want to make text box four enter email details so here we have write input type is equal to text and name is equal to email under this field user can enter their email details lastly we have right text area filled with name is equal to message under this field user can enter any query which has asked to owner of website for submit form data here we have write input type as equal submit name is equal to send and value is equal to sent by click on this button user can submit their details now we have go to send email controller and make send method for request form request under this method first we want to validate data so here we have write dollar this with validate method this method will run the validator rules against form data under this method first we have right dollar request variable and in second argument we have to define data validation rules in array format so here first we want to validate user name data so in key we have write name and in value we have write required rules this rules will check this name field has some data otherwise it will display error same way we want to validate email data so here in key we have right email and in value we have right required rules an email this will check email field has some data and it will check this must be an email lastly we want validate message data so here in key we have write message and in value we have write required that means this field data also required for submit form if any of the validation rule not follow then it will load index method send email view file with validation rules now we have go to send email dot blade dot PHP file and here we want to display validation message so here we have right at the rate if statement and under condition we have write count function errors greater than zero this condition will check there is any validation error has occurred then it will execute if block of code so first we want to close if block so here we have write at the rate and if under this block we have right division tag with class is equal to alert and alert danger class of bootstrap for display validation message we have right at the rate for each loop and under condition we have right dollar errors variable with all method as dollar error variable this all method will fetch error message from dollar errors variable which we can fetch from dollar error variable and foreclose for each loop here we have right at the rate end for each for display error here we have right list tag in between we have right dollar error variable expression it will display validation message on we page now we want to set root of this both method so we have go-to roots folder web dot PHP file under this file we have right root class with get method with two argument in first argument we have writes and email and in second argument we have writes and email controller at the rate index method so when in browser when we have type base URL slash send email then it will called index method of send email controller after this we want to send route 4 send method so here we have write route class with post method and under this method we have writes and email slash send and in second argument we have writes and email controller at the rates and method so when in-browser went form has been submitted and send request to send method then it will execute send method of send email controller now we want to check first validation working properly or not so we have go to command prompt and write PHP artisan serve command this command will run our eval application here in browser we have right base URL slash send email then it has load contact form on web page now we have directly click on submit button after directly click on submit button then we can see validation message on web page so here our validation rules working properly in Louisville now we have procede for send email so we have go to command prompt and first we have stopler of L server and type this command this command will make mailable class with name like send mail dot php' under this mail folder which we can see here now we have opened this and mail class and under this class we have defined one public dollar data variable this variable we will use for make dynamic email body here we have can see construct method function so here in this function argument we have write dollar data variable and under this method we have right dollar this with data variable is equal to dollar data variable here we have store construct method dollar data argument we have store under this public dollar data variable now we have go to build function this function build message in this function we can define from which email ID email should be sent subject of email an email body from view file so here we have rightt return statement with dollar this with from method and under this method we have write John at the rate webs lesson dot info so here we have defined email must be sent using this email address after this we have right subject method and under this we have right new customer inquiry here we have defined static subject of email here we can also make dynamic subject also then after here we have right view method and under this we have right dynamic email template which is view which we have already make under view folder email body has taken from this view file code now we have want pass value under this view file so here we have write with method with two argument under first argument we have write data and in second argument we have write dollar this data variable by using this width method we can access value of this data variable under dynamic email template view file now we have open dynamic email template view file here we can see some text now we want to display name of user who has filled the form so here we have right open and closed two curly braket and between this we have right dollar Dayton named variable so whichever name user has filled under form that name will be appear in email body also after this we want to add customer query which he has right under message tag must be appear in this email body so here we have right open and closed to curly bracket and between this we have right dollar data message variable this way we have make dynamic email body now we want to set email configuration for send email from laravel application for this we have go to dot env file and here in male driver option we have define SMTP driver for send email in second option we have defined male host so here we have defined our male host address here you can define your email host name in third option we can see male port so here we have right ad here we have define our email host here you can which every port number has been used by your host in fourth option which is male user name here you have to define your email address username in fifth option we can see mail password here also you have to define your email address password and last option which is mail encryption set to null so this all information must be provide for email configuration so here our email configuration is ready now we have send email controller here first we have defined mail class for this here we have write this used statement by using this code we can use Louisville mailer class after this we have right use statement with F forward slash male forward slash send mail here we have defined mailable send mail class by using this class we can send email now we have go to send method and here we have write dollar data variable is equal to array in a ray first key we have right name and value get from dollar request name variable and in second key we have right message and value get from dollar request message variable this way we have store required form data under this dollar data variable in a ray format now we can pass the send email mailable class and that class pass this data into dynamic email template view file so first we have right male class with two method and under this method we have right email address here we have defined email address to which all email will be sent after this we have rights and Method and under this method we have right new sendmail class object with dollar data variable as argument here we have create send mail class object this method will send a message using the given mailer now we have rightt return statement with BAC method this method will redirect page to previous page location after this we have right with method with two argument in first argument we have right success and in second argument we have right success message this method will add a piece of data to the view lastly we want to display success message in send email dot blade dot php' view file so here we have right at the rate if statement and under condition we have right dollar message is equal to session class get method and under this we have write success this condition will check there is any message with named success has been store under session then it will store that into dollar message variable and it will execute if block of code under this block we have used bootstrap library alert class and here we want to display message we have right open and closed to curly bracket and between this we have right dollar message variable it will display success message on webpage now we have check output in browser so friends we have already checked form validation is working or not and it is working now we have refresh page after a refresh of webpage now we have start filling form data so in name textbox we have right Peter Parker an email field we have right Peter Parker at the rate gmail.com and in message field we have write some query after filling of all form field now we have click on send button after click on send button it has takes some time for send an email from this Louisville application after successfully sending of email we can see success message above the form now we have go to email inbox and check email has been received or not so here we can see email with subject like new customer inquiry has been received here and an email body we can see Peter Parker name and below we can see query which has been written by Peter Parker in email body so this way we can send email in Louisville by using mailable mailer if you have any query or input regarding this video tutorial please comment your query or input in comment box or if you like this video tutorial please share with your friends or even you can also share on social media also if you want to get more update regarding our video tutorial please subscribe our YouTube channel forget more update regarding release of future video lastly keep watching our YouTube channel thanks for watching this video tutorial
Info
Channel: Webslesson
Views: 78,543
Rating: undefined out of 5
Keywords: send email, laravel, laravel email, mail configuration in laravel, laravel mailer, how to send email in laravel, send mail in laravel, email in laravel, email send laravel, send email laravel, send email laravel localhost, laravel email send, laravel mail send
Id: rn0BHdqrock
Channel Id: undefined
Length: 19min 29sec (1169 seconds)
Published: Sat Sep 22 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.