Skip to main content

Posts

Showing posts from 2018

PHP Send email with attachments without saving files PHPMailer

Send email with attachments without saving files PHPMailer Keep follow the below steps to send email with multiple attachments without saving files on local using phpmailer :- 1) Create a project folder and navigate to our new project folder. 2)Install phpmailer by using below command   composer require phpmailer/phpmailer 3) Now create a index.php file with the below code <?php // Import PHPMailer classes into the global namespace // These must be at the top of your script, not inside a function use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; if(isset($_POST['submit'])) { //Load Composer's autoloader require 'vendor/autoload.php'; $mail = new PHPMailer(true);                              // Passing `true` enables exceptions try {         //Server settings     $mail->SMTPDebug = 2;                                 // Enable verbose debug output     $mail->isSMTP();                                      // Set maile

PHP Add days into date but ignore weekends

PHP Add days into date but ignore weekends If we want to add days into php date then we can add days by below code: Add n days to current date   <? php $date = date("Y-m-d") ; echo date ( 'Y-m-d' , strtotime ( $date . ' + 1 days' )); echo date ( 'Y-m-d' , strtotime ( $date . ' + 2 days' )); ?>   Add n days to specific date   <? php $date = "2018-07-23" ; echo date ( 'Y-m-d' , strtotime ( $date . ' + 1 days' )); echo date ( 'Y-m-d' , strtotime ( $date . ' + 2 days' )); ?>     Question : But What if we want to add days to date but ignore weekends day like Saturday and Sunday ? Answer Yes we can ignore by using Weekdays with nth days. here is the example of it :- Add n days to php date but ignore saturday and sunday <?php $date = "2018-07-23" ; echo date( 'Y-m-d', strtotime($date. ' +200 Weekdays

Install MongoDb latest version on linux

  Install MongoDB on linux?(Latest Version)  In this tutorial we will explain how to install MongoDb on linux ubuntu or mint. here we are installing latest version of MongoDb but you can install any version . Here we have 3 sections for this tutorial . 1) Install MongoDb 2) Common Issues and errors during installation 3) Test MongoDb Server So keep follow the below steps to install MongoDB. 1) Download MongoDb To download mongodb , first go to the  mongodb.com and browse download page or you can directly go to the https://www.mongodb.com/download-center page and download the appropriate version according to your OS. 2) Now after download it , copy the zip file and create a folder "mongo" in home directory and paste it into it and extract it . now create a new folder "mongo-data" to store database in it. here we are changing our default database storage folder so our data will be save in this directory. After this our directory structure will

Create snippets in sublime text editor

How to create snippets in sublime text editor We can add code short-codes or snippets in sublime text. For example we creating a  echo '<pre>'; print_r($YOURARRAY); echo '</pre>'; exit; short code, after creating snippet we don't need to write whole line of code every time , we just need to type eche and then press tab button enter button , sublime text will auto generate that code for you. So here is the simple steps to create snippet to create own code shortcuts in sublime text. Go to Sublime Text Top Menu and click on  Tools->New Snippet.A new file will open. Now paste the below code <snippet>     <content><![CDATA[       echo '<pre>'; print_r(${1:ARRAY}); echo '</pre>'; exit;       ]]></content>     <description>PHP: Pretty print_r</description>     <scope>source.php</scope>     <tabTrigger>eche</tabTrigger> </snippet> and sa

Codeigniter - Remove index.php from url

Remove index.php from url in codeigniter By default codeigniter(CI) includes index.php in url but we can remove index.php from url easily by using htaccess.   To remove index.php from your codeigniter website url ,  create a .htaccess file in root directory and  paste the below code. RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L]     Now navigate to your website and you can access your  website without including index.php.  

Login with Microsoft Live Account PHP

How to Login with Microsoft Live Account PHP This post explains you how to implement login Microsoft Live account using PHP. For login ,  we need  Client Secret Key and Client ID . Click Here To create Microsoft application that will provide client id and password. Open the above url and fill "app name" and "redirect url" . Application id is your client ID and application secret is client secret key. Our api is created successfully. Now we need to create 2 php pages one for login and second one for receive user data as response from microsoft app. First create a link on your login page , that will redirect to user on our microsoft login page(mslogin). <a href="mslogin.php">Login with Microsoft</a> Then create a page mslogin.php and paste below code mslogin.php <?php $client_id = "YOUR-CLIENT-ID"; $redirect_uri = "https://your-site.com/response.php"; //you can also use localhost url for testing