Send email using Gmail SMTP in Laravel 5.*

Hi there, hope you are not in trouble with your application email sending feature. I am using mailtrap.io for email testing on the development server. It is good, but one problem is all email are going mailtrap’s Demo inbox, not to users individual email. And my client wants to check all email templates and functionality on the development server, with various emails and here I need to look for an alternative solution. By the way, I am using Laravel’s default email function.

So, here is the process that I follow and hope it will help you too. Don’t worry it’s simple.

Step – 1: Update the google account permission for allowing access less secure (third party) apps.

  • Go to your Google account dashboard by clicking on this link https://myaccount.google.com/security#connectedapps  or My Account button on Gmail
  • And take a look at the Sign-in & security -> Connected apps & sites -> Allow less secure apps settings.
  • You must turn the option “Allow less secure apps” ON.

Step – 2: First open .env file and update email setting parameters

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your-email@gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls

Look at the PORT and ENCRYPTION, I use 587 and tls (Transport Layer Security) respectively. Try to maintain this configuration, otherwise you will get the error. Though both are used as default in configuration (config/mail.php) file.

Step – 3:  If you get any exception error regarding OpenSSL certificate. Then you need to add following code to mail configuration file. Open mail.php file located in config/mail.php and add following code. In my case, I added at the bottom.

// send email locally – only for development server, do not use it on production server

‘stream’ => [
‘ssl’ => [
‘allow_self_signed’ => true,
‘verify_peer’ => false,
‘verify_peer_name’ => false,
],
],

Note: It is suggested, not to use this configuration on your production server, because of security purpose.

 

I am really glad if this information is helping anyone. So, let me know your feedback or any alternative way/solution you know for this issue.

I would glad to help you, please ping me at me[at]skpaul[dot]me if you need any support.

Advertisements

Integrate, install, test and debug SSL Certificate

I am working on a project and PM request me to create a CSR (Certificate Signing Request) for purchasing a SSL certificate. I do some research and of-course Google, suddenly get this informative hands-on video tutorial with commands in text format. So,just watch the video with full concentration and use the commands when you need it.

BTW, there is also a video on How do you get and integrate a free SSL with your domain/site.

So, Njoy and visit the link.

 

How to Integrate, install, test, debug #SSL Certificate. 5 videos cover many things. Also with free SSL Certificate from #Letsencrypt

  1.  Create CSR and Purchase and Install an SSL Certificate — https://serversforhackers.com/c/purchase-and-install-an-ssl-certificate
  2. Testing and Debugging SSL Certificates — https://serversforhackers.com/c/testing-and-debugging-ssl-certificates
  3. Self Signed SSL Certificates for Development — https://serversforhackers.com/c/self-signed-ssl-certificates-for-development
  4. Purchase & Install a Wildcard SSL Certificate — https://serversforhackers.com/c/purchase-install-a-wildcard-ssl-certificate
  5. Letsencrypt for Free & Easy SSL Certificates — https://serversforhackers.com/c/letsencrypt-for-free-easy-ssl-certificates (**FREE SSL)

And here is all together — https://serversforhackers.com/s/integrating-ssl-certificates

Here is the man (Chris Fidao) who secure my and your life too as well as time.

THANKS Chris Fidao.

Rapid or fast development in Sublime Text 3

We, developers like to write codes, but what if you need to write 1000000000 lines of code?
Let me know your answer on comment 😉

Here comes snippet, What is snippet?
Snippet a small piece or brief extract. it’s a brunch of code that is generate by shortcut key.

Now we know create some snippets for faster our development time. And we need function every where, so we will create a snippet, that we dont need to write same code again and again

Step-1: Open Subline
Step-2:Tools > Developer > New Snippet, Now you will get a file like this

Step-3: Update the codes with below codes

Look at the underline area the function is public and we use ${1} and ${2}. what does it mean?

Continue….

Open/Start Sublime Text in (windows) command line shortcode with a specific project

Open your Sublime Text2/3 by shortcode “subl .” on command prompt with a specific project.

 

We often need to open projects in between another project for some updates/support. As I am using Sublime Text 3 for coding, so I open/drag the folder to the editor project panel. But, It is risky and time consuming to search any file from all open projects. So, I was looking for a quick solution that I can easily open the project on a new window of Sublime Text. And here is the process…

 

Step 1:
Press Menu Key/Windows Logo Key > type “This PC\My Computer”, Write click on it and click on “Properties”
Or: Control Panel > System and Security > System

 

Step 2:
Click on the “Advanced system settings” > click on the “Environment Variables” (at the bottom on the new popup window)

 

Step 3:
Now you will get another window that have 2 sections User Variables and System Variables

> Add user variable by client on the New button
Variable name – SUBLIME_HOME
Variable value – C:\Program Files\Sublime Text 3\ (it depends, when you install Sublime Text. I install in C drive and it was Sublime Text 3)

> Now in system variables list, select “Path” variable and client on edit button. Add
“;%SUBLIMETEXT%” at the end of the path variable value.

Shortcut 😀 : just paste “;C:\Program Files\Sublime Text 3\” (it depends, when you install Sublime Text. I install in C drive and it was Sublime Text 3) at the end of the Path variable value. There may be existing values, so keep in mind to add a “;” before your value as above example.

 

Step 4:
Hope you are in project folder > Press Ctrl+Shift and write client > Client on the “Open command window here” > type “subl .”/”sublime .” (remove qoutes and add a dot with a space) on command prompt > And the project will open in a new window of Sublime Text.

Or you can open command prompt any where and navigate to the specific project folder and run the “subl .”/”sublime .” code, the result will be same.
Or You can just open the command prompt and run the command “subl”/”sublime” to open the Sublime Text

 

**Check your Sublime Text installation folder (mine is C:\Program Files\Sublime Text 3\), check the name of the .exe file. It should be “subl.exe” or “sublime.exe” and use “subl”/”sublime” depends on the exe file name.

 

Check this video for a quick demonstration and let me know your feedback.

How to define Global Variable or Constant in Laravel

We often need to define global variables/constants for our application, like Status, Conditions, Countries (we can put all countries in table as it will be along array/object), also weekdays, weekends and e.t.c. vary on projects.

Status (Active, Inactive) and Conditions (Ok, Good, Better, Best) or Grade (F, C, D, A, A-, A+), so like these type of variables/constants,  we write same code multiple times. But if we set all of these as Global Variables then we can use these anytime, anywhere in application.

 

 

And here I am presenting how to define GLOBAL Variable/Constant in Laravel 5.2. (This is not the only way, but I like it)

  1. First create a file named constants.php on config directory
  2. And code some variables like below

return [

‘STATUS’ => [

1 => ‘Active’,

0 => ‘Inactive’

],

‘Conditions’ => [

1 => ‘Ok’,

2 => ‘Good,

3 => ‘Better,

4 => ‘Best’

 

],

‘GRADE’ => [

‘A+’ => ‘A+’,

‘A’ => ‘A’,

‘A-’ => ‘A-’,

‘B’ => ‘B’,

‘C’ => ‘C’,

‘D’ => ‘D’,

‘F’ => ‘F’

]

];

  1. Now, how can we use/access this Global Variables? Very easy, and we can also access these variables on view too.

Config::get(‘constants. STATUS’); // it will output status array.

Or, if we want a specific one element then

Config::get(‘constants. GRADE.F’); // output: F

  1. And lastly we can also set Global variable only for the current request. This will not persist.

Config::set(‘constants. Conditions.5’, ‘Not Stable’)

 

And finally – if you like this article please inspire me by posting a comment (at below) for the next article 😉 . And I don’t mind if you want to share among with your friends, bocz. Sharing’s Caring.

 

Credit: google, stackoverflow, Laravel.io, Laravel docs and etc.

Multiple sessions or Different logins at the same time on firefox

Multifox – is an awesome and very useful plugin for me. If you need to login multiple accounts at the same time, what did we do naturally, we used multiple browsers. But with this plugin on Firefox, you can access as many accounts as you want.

Mozilla Addons link -> click here

But if your browser’s version doesn’t support the plugin, you can try here with an old version from their website Getmultifox.com

For details and getting started check here

 

N.B.: Chrome already have this feature builtin on Settings > People > Add preson