How to Send Bulk Email using PHP with PHPMailer & Ajax JQuery

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 multiple or bulk or mass email from PHP script by using PHP mailer library with Ajax query in our previous post we have seen how to send email and PHP by using PHP mailer so now we have go to some advanced concept and use that library for send bulk email form our system here we have used query and Ajax functionality for send mass email from PHP script so all process will done it back inside and multiple email will send to particular email without refresh of web page suppose in your web application and you want to send newsletter of new product multiple customer then at a time you cannot send email to single customer one by one but at that time this feature will help you can you can send bulk email newsletter to all customer and single click and email will be send the customer without refresh of web page because we have used Ajax and query for this here we will make simple system from which not only we will send bulk email but also we can also send single mail also you now we are going to learn this topic this is our testing database and in this we have simple customer table with three table column like customer ID customer name and customer email in this table we have already inserted some customer data so we will first this data from this table and after this we will write code for sent an email to customer by using PHP with Ajax query and PHP mailer library this our index page and on this page we have already loaded this JavaScript libraries query and bootstrap library in head section by using this thing now we have go to body section and make one HTML table with four table call and light customer name email select an action now under this table we want to load customer data from table with check box and email sent button for load customer data from table so first we want to make database connection so we have write doll or connect variable is equal to new no class with three argument like my SQL host is equal to locale lost database name is equal to testing username set to root and password set to blank after making of database connection so now we have right dollar query variable is equal to select star from customer table order by customer ID this query will fetch data from customer table now we have right dollar statement variable is equal to database connection string dollar connect variable with preparer statement with dal or query variable this statement will prepare query for execution after this we want to execute query so we have right dollar statement variable with execute method this method will execute select query after execute of query now we want to get query execution result so we have right dollar result variable is equal to dollar statement variable with fetch l method this method will fetch data a query execution and store into this stall or result variable now we have go to HTML table and here we have write PHP code like dollar count variable value is equal to zero we will increment this variable value and we will use this variable value to generate dynamic button it below this we have write for each loop and under condition we have write dollar result variable as dollar row variable by using this for each loop we can fetch data from this dollar result variable under the sloop first we have right dollar count variable is equal to count variable plus one here we have increased dollar count variable value by one on every interval now we want the print customer data an HTML table so we have right taco statement with HTML code like open and close table row tag in first column we want to print customer name so we have rights open and close table data tag and between this we have right dollar row customer name variable in second column we want to display email it so we have rights open and close table data tag and between this we have right Dollar Road customer email variable in third column we want to display displayed checkbox and by clicking this checkbox we can define customer to whom we want to send email for display checkbox we have write input type as equal to checkbox with attribute name is equal to single select class is equal to single select we will use this class name as selector inch query code in this checkbox here we have right data email attribute is equal to dollar role customer role variable and in date the name attribute is equal to dollar role customer name variable we will fetch both attribute value and query code in last column we want to display button for San single email so here we have right button type is equal to button name is equal to email button and class is equal to email button we will us this class name as selector and square e code in this button we have right to the attribute is equal to dollar count variable data email is equal to dollar wrote customer email variable and data name attribute is equal to dollar wrote customer name variable we will fetch the salt attribute value and query code and lastly in button we have write data action attribute is equal to single by using this attribute value we can know this button is used for sensing the li mail in table lastly we want to display bulk email button so we have to find one more a table row tag and in this we have defined two table data tag you in second table data tag we have divine button type is equal to button name is equal to bulk email class is equal to email button it was equal to bulk email and data action is equal to bulk here we have used same class name email button which we have used above but here in data action variable is equal to bulk from this attribute value we can identify this button is used for send both mail and query code now we have moved to write query code here we have write dollar with button class name email button with click event so when we have click on send single or bulk email button this code will execute under this first we want the disable button so we have right dollar this with attribute method with two argument and in both argument we have right disabled attribute this code will disable particular button after this we want to get rid a particular button on which we have clicked so we have right variable it is equal to dollar this with attribute method and under this we have right to add attribute this code will get value of it and store into this set variable now we want to get value of data action attribute from this we can know button on which we click is for cents single email or bulk email so we have right action variable is equal to dollar this with data method and in this method we have right action variable this code will fetch value of data data action variable and store into action variable now we have defined variable email data variable is equal to array in this variable we will store email data like customer email a name in a ray format after this we have write if statement and under condition we have right action variable is equal to single here this condition will check if action variable value is equal to single then it will execute if block of code otherwise it will execute tells block of code supposed action variable value is single that means we have click on button force and single email it will execute if block of code and this block we have write email today - variable with push method this method will store data in this variable in array format under this method we have right email object with value get from dollar this state an email variable here we have define email object and in this object we have get value from particular button data email variable in which we have stored customer email same way we have at another object name with value get from dollar this state a name variable here we have defined name object and in this object we have kept value from particular button date a name variable in which we have store customer name this way we have store email day like email and name fetch from button data attribute and store into email data variable in array format in case of sent of single mail but suppose action variable value is not equal to single then it will execute else block of code and in this block we have defined customer data for sent bulk email and here we will fetch customer data from check check boxes data email and name attribute so here we have right dollar with checkbox class single select with each method with function by using this each method we can fetch all checkbox in which we have defined this single select class one by one after this we want to fetch checkbox of only let which are checked by user so here we have if statement and under condition we have write dollar this with pop method and under this we have write checked is equal to true this condition will check particular checkbox is checked or not if it is checked then it will execute if block of code otherwise no action has been taken suppose particular checkbox has been checked then it will execute if block of code and this block we have write email today to variable with push method this method will store data in this variable in array format under this method we have write email object with value get from dollar this day to email variable here we have define email object and in this object we have get value from particular checkbox data email variable in which we have store customer email same way we have add another object name with value get from dollar this state a name variable here we have defined name objects and in this object we have get value from particular checkbox state a name variable in which we have store customer name this way we have store email data like email and name fetch from checkbox data attribute and store into email data variable in a raid format in case of sent of single mail after getting email data for San single or bulky mail now we have start right Ajax requests and in this we have first right URL option set to send mail dot PHP page here we have sent requested to this page in second option we have right method option and in this option we have right post method so here we have used post method force and data to server in third option we have right data option in this option we can define which data we want send to server so here we have define email data which we want send to server in this variable we have store customer email and name data in array format and fourth option we have right before send callback function this function has been called before it will send request to server in this function we want to change text of particular button so we have right dollar with a selector value get from a variable with HTML method and in this we have right sending this code will change particular button text after this and dysfunction we want to change background color of particular button so we have right dollar with it select her value get from a variable with AD class method and under this we have right bootstrap button danger class this code will change particular button background change to red color lastly in Ajax request we have right success callback function this function has been called if Ajax requested completed successfully and this function will receive data from server which we can fetch from this data argument under this function we have right of statement and under condition we have write data variable value is equal to okay this condition will check if this variable value is equal to okay then it will execute if block of code otherwise it will execute else block of code suppose data variable value is equal to okay then will execute if block of code and mail has been sent successfully and under this block first we want to change particular button text so we have write dollar within selector value get from a variable with text method and under this we have write success this code will change button text to success after this we want to change background color of button so we have write dollar within selector value get from a variable with removed class and in this we have right button danger class this code will remove this class from button class attribute same way we have a gain write dollar within selector value get from a variable with removed class method and under this we have right button info class this code will also remove this class from button class attribute now we have a gain write dollar with head selector value get from made variable width add class method and under this we have right button success this code will change particular button background to green color but suppose data variable value is not equal to okay that means there is some error an email sent and that will execute tells block of code and under this block if we have right dollar within selector value get from a variable with text method and under this we have right data variable this will display value of data which received from service scrip will be display on button text lastly we want to enable particular button so we have right dollar within selector value get from a variable with attribute method with two argument like disabled and false this code will enabled particular button now we have moved to write PHP code for sense single or bulk mail on send mail dot PHP on this page we have write a statement and under condition we have rights of function we'll dollar post email data variable this condition will check if value of this variable is set or not if set then it will execute if block of code suppose value of this variable is set then it will execute if block of code and under this we have right requires statement with class folder name slash class dot PHP Miller dot PHP here we have include this PHP mailer library in this code and we have store this library in class folder after this we have defined dollar output variable is equal to blank value in this variable we will store data which we want to send back to Ajax request now we have right for each loop and under condition we have write dollar post email data variable as dollar row variable by using this loop we can fetch data from this dollar post email data variable one by one now we have create object of this PHP mailer class so we have write dollar mail variable is equal to new PHP mail or class here we have create dollar mail object of this PHP mail or class after this we start writing PHP mailer configuration for send email so we have write dollar mail object with is SMTP method this method sets Miller to send message using SMTP credential below this we have write dollar mail object with host is equal to SMTP auth dot secure server dot net here we have the font SMTP host server after define host server now we have a gain write dollar mail object with post is equal to 18 here we have the font smtp server port now we have write dollar mail object with SMTP auth is equal to true here we have the font SMTP authentication is like username and password is required force and email below this we have write dollar mail object with username is equal to SMTP username here you have to define your SMTP username if you have then right here after define username now we have write dollar mail object with password here you have to define your SMTP password if this both are some key P user name and password proper then it will send email then after we have right dollar mail object with SMTP secure is equal to blank here you can write SSL or TSL if you have otherwise leave blank now we have a gain right dollar mail object with from option here we can define email from which you have received email so here we have right to email from which we want to send email below this we have write dollar mail object with from name is equal to dollar post name variable here we have sets from name of the message in this name will be viewed to receiver now we want to set receive our email address so here we have write dollar mail object with add address method with two argument and first we have write dollar roll email and in second argument we have write dollar name variable so this way we have set receiver information below this we have a gain right dollar mail object with is HTML method with argument true here we have set message type to HTML otherwise that email format will be plain text now we want to define subject of email so we have write dollar mail object with subject is equal to lorem ipsum text here we have defined value of email subject and lastly email configuration we want to define email body so we have write dollar mail object with body is equal to lorem ipsum text in HTML format so here we have define email body in HTML format so this way we have set email body so here email configuration is completed with all necessary information and now we can send single or bulk email so force and email we have right dollar resolve variable is equal to dollar mail object widths and method by using this method we can send single of bulk email and this method will return status of email send which we have store and dollar result variable after store email son status in dollar Rizal variable now we have write of statement and under condition we have write dollar result called variable is equal to 400 this condition will check if this stall are resolved called variable value is equal to 400 and it will execute if block of code suppose dollar resultcode variable value is equal to 400 that means mail is not sent and that will execute if block of code and under this we have right dollar output variable and in this variable we have a Pandaria from this dollar result full error variable this way we can store email not sent error in dollar output variable now here we have write of statement and under condition we have write doll or output variable value is equal to blank here if the all our output variable value is equal blank then it will execute if block otherwise it will execute else block of code suppose dollar output variable is blank that means all mail sends successfully and it will execute if block of code and under this block we have write echo statement with okay text which we have send to Ajax requests but dollar output variable has some value that means there is some error has been occurred while sanding of any email so it will execute tells block of code and here we have right echo statement with dollar output variable value which we have send to Ajax request so here our code is ready for how to send single or bulk email by using PHP mailer with Ajax as queries so we have save it and check out what in browser friends here we can see that when page has been loaded into browser then on web page we can see that customer name their email address with one check box for selection and once and button and below this we can see send bulk button also by the single send button we can stand single emails a particular customer and suppose we want to send bulk email then we can check the checkbox of particular customer to whom send email and click on send bulk button by clicking this button we can send bulk email to check check box now first we have check single send email so here we want to send email to John Unger so here we have click on this button after click on single send button has been disabled in this button text has been changed to sending and background color has been changed to orange after successfully sending of single email button text has been changed to success and background color has been changed to green that means single email has been successfully sent to John Junger email now we want the test bulk email sending so we have select first three check box and click on send bulk button after clicking on send block button has been disabled into text has been changed to sending and it's back ground color has been changed to orange after successfully sending of bulk email button text has been changed to success and background color has been changed to green that means bulk email has been successfully sent the first three customer now we have check and box of three customer so this is Kathleen Nicholson and here we can see email has been received same way we have Check Into Vance had inbox and here also we can see one Webb's listen email has been received and lastly in John Junger inbox also here we can see two Webb's list an email because we have sent single and bulk email to this customer so in his inbox we can see two email so here our code is working in all stage level this type of feature is very useful while you want to send large number of email and single click of button and here we have use Ajax and query so all process has been done on backhand side without refreshed of webpage if you have any query regarding this video tutorial part please comment your query in comment box and 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 you
Info
Channel: Webslesson
Views: 39,583
Rating: undefined out of 5
Keywords: phpmailer ajax, send mail using ajax, email in php, how to send bulk email using php, send mail using phpmailer from localhost, email php script with ajax, send mail using phpmailer jquery ajax, sending mass email using php, how to send bulk email in php, php mail script with ajax, php send email, send email in php, send email using php, send html email php, sending email in php
Id: d86cerLiWcg
Channel Id: undefined
Length: 26min 31sec (1591 seconds)
Published: Tue Oct 17 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.