Simple Way To Send Email In Codeigniter 4 via Gmail SMTP

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends today we are going to see how you can send emails from codeigniter 4 applications with gmail smtp the first thing you have to do is to download latest version of codeigniter 4 php framework go to google and search for codeigniter for gethub click on this gethub link then click on this code igniter 4.1.5 latest version click here to download zip file of this code igniter once download finished extract it and open it in your text editor for me i will use visual studio code for this tutorial second thing you have to do is to enable less secure of your gmail account for allowing user to send email via gmail smtp just click on manage your account button click on security link then scroll down and find less secure app access section as you can see my account less secure is off to turn on click on this blue link then change this toggle button position to blue color as you can see the less secure access turned on automatically google send notification about this updates so let's continue back to visual studio code and rename n file to dot env uncomment this environment variable and change this to development mode go to appconfig email.php file and update some variables create access and add the following text to it this will help us to remove index.php from url back to appconfig app.php file and remove this index.php here open terminal and enter php spark serve for running our application as you can see we are on codeigniter4 create new controller by entering php spark make colon email controller command in terminal so email controller has been created add new get root for contact form let's create this view as you can see we have this contact page link bootstrap on this page let's continue design this page with bootstrap classes this form will contains name email subject and message input fields as you can see we have this error that says the undefined function set underscore value to solve this we need to load url and form helpers in construct function inside email controller class as you can see our contact form has been completed create new post route for sending email let's use this root name to contact form action attribute don't forget csrf on this form and add send method inside email controller class first validate the form inputs name must be required email must be required and be a valid email subject must be required message must be required if there are validation errors let's display errors on contact form if i submit this form without filling any input we redirect it back to contact form let's show validation error under each input field on this form let's test as you can see our validation works perfectly let's continue sending email will require an internet connection that is why we must check if we are connected on internet or not let's write this function for check internet connectivity let's check if i fill all required inputs and submit this form when i am not connected to internet i get this message that shows me that i am not connected to the internet but if i submit this form when i am connected to internet i get this message that shows that i am connected to the internet let's continue if there is no internet connection redirect user to contact form with error message so if we are connected to internet let's send email to a given recipient if email not sent return user to contact page with error alert message but if email sent successfully return user to contact page with success alert message in order to display error or success alert on this form we need to add this on this form now we are ready to test our codes fill sender details in this form if i submit this form without connected to internet we get this error message that show me that i am not connected to internet but if i submit this form when we are connected to internet we have this success alert and we don't have any error let's see if the email sent or not as you can see we received email from codeigniter for contact form we received email from benjamin let's send email again as you can see we receive her another email from doe you can reply this email to the sender email you can also send email message from template file by using rendering view let's show how to do that create new message variable then pass message variable to this view create this view let's test as you can see we received also new email from noella you can receive responsive html email body here instead of this plain text let's see how you can implement that i already have this html email template we are going to send this html email example just copy this html markup and paste inside this email template file replace this with past message variable let's test send new email as you can see i received a new email from venon johnson and also is a responsive email friends that is how you can send emails by using gmail smtp and codeigniter4 thanks for watching this video
Info
Channel: Irebe Library
Views: 436
Rating: undefined out of 5
Keywords: irebe library, codeigniter tutorial, codeigniter 4 tutorial, ci4, send email, send email via smtp, send email with google, send email in codeigniter 4, send email with ci4
Id: RhbRedtMlto
Channel Id: undefined
Length: 21min 0sec (1260 seconds)
Published: Fri Nov 19 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.