How To Send Emails In PHP With Symfony Mailer Using Gmail SMTP With Google App Passwords

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello developers welcome to gilgeek if I my name is said kohans although I hope you have a wonderful day in this video I will show you how to send emails with attachments and images in PHP using Symphony mailer also I'm gonna show you how to generate and use Gmail app password you can use this method in any PHP project or Scripts I'm using Google SMTP server to sending my emails let me show you how to generate an app password for your Google account [Music] open your Google account settings I want to use this Gmail as SMTP in my PHP program go to the security tab to access the app password option first you should enable The Twist the verification in your Google account now you should sign into your Google account select other from the list and choose a cost same name for it I will choose my PHP SMTP app then click on generate button okay it's your app password save it somewhere and use that at the right time inside your PHP script to authenticate your Gmail SMTP let me show you how to install Symphony mailer to insert Symphony mailer you need composer composer is a tool for dependency Management in PHP you can download and install it from getcomposer.org [Music] this is my localhost folder after you install composer you can install Symphony mailer using CLI Powershell command prompt or terminal by running this line of code okay now we have Symphony mailer source code here and I'm adding some files to attach them to my emails in my next step let's open vs code and start coding I will create an email.php file to code my email script inside it load composers autoloader and import Symphony mailer classes that we need to use I will Define a transport object you can add your SMTP server and configuration in this format creating mailer and email objects adding from and two email addresses you can use string object and array as their perimeter you can add multiple recipients like this also you can add name for sender or recipient check SIM from the mailer documentation about that okay now I'm adding my Gmail SMTP information here I'm using the Google app password that I generated and saved in the past username password SMTP server and port adding from address and adding two address set an email subject set plain text version of the message and set the HTML version of the message adding email sending comment this is how we can send our emails okay now let's test the descript just open the email.php file in the browser well the email must have been sent checking my inbox and the email has been received [Music] now let's add some attachments to this email you can add attachments from the path like this I added some text files and this is how you can embed images inside email with an embed name I added some images here now let's display embedded images in the HTML you can use the syntax CID column Plus image embed name to display reference images let's check these text files and images in my system folder okay now let's send an email with these attachments just refresh the email script well as you can see we have an email with attachments let's check it exactly [Music] I have this command to send emails now let's add some features to check the email status now I will show you how to debug emails with exception handling you can check the email status and do something when an error occurs exceptions are used to change the normal flow of a script if a specified error occurs inside the catch you can display any error and inside try you can display any successful notice and you can check real errors that are outputted from Symphony mailer like this also you can use the get debug method to check transport exception check debugging emails from Symphony mailer documentation for more information [Music] OK let's send another email email has been sent and we are seeing a successful message now let's make an error on purpose and try to send a new email as you can see the program returned my custom error because something is going wrong let's go to check real errors that are outputted from Symphony mailer and it's an error from Symphony mailer that says fail to authenticate on the SMTP server because of bad credentials [Music] let me show you something you can add carbon copy blind carbon copy reply to and priority like this now we have a complete PHP script for sending emails with attachments using Symphony mailer Google SMTP server and a Google account with an app password let's send some emails again thank you for watching this video [Music] foreign [Music]
Info
Channel: gilgeekify programming
Views: 3,921
Rating: undefined out of 5
Keywords: php programming, programming, php developer, backend developer, backend php developer, php developer skills, php for beginners, php tutorial, php tutorial for beginners, full stack developer, developer, learn php, backend developer roadmap 2022, what is php programming, php developer salary in india, php, symfony mailer, google app passwords, gmail app password, google smtp, mailer script, send email with php, php email sender, php google smtp, symfony php framework, php app
Id: Dwo1UOZoElI
Channel Id: undefined
Length: 14min 13sec (853 seconds)
Published: Wed Sep 07 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.