Create Gmail STMP and install for WordPress, Laravel, php…
- 24-07-2022
- trienkhaiweb
- 0 Comments
SMTP is a protocol for sending email, fortunately, google provides us with a solution to be able to send mail from google's server for free. Sending emails through google's STMP has the following benefits:
- High email delivery success rate (almost 100%).
- No need to install mail server (if you are using VPS).
- Your mail is less likely to be marked as spam like using a self-installed mail server on a VPS because, in essence, you are asking google's mail server to send mail.
To create Gmail SMTP, at least we need a google email account, next we need to perform the following steps sequentially:
Mục lục
Step 1: Access your google account:
Step 2: Access the security menu and enable 2-step verification:
Step 3: After enabling 2-step verification, proceed to create an application password:
After creating, google will provide the application password, we need to save it to use for SMTP configuration
Step 4: Install SMTP Mail for the website:
For WordPress:
install the plugin EASY WP SMTP or WP Mail SMTP by WPForms and use the following configuration:
- SMTP Host – enter smtp.gmail.com .
- SMTP Port – The default SMTP Google is 465 for SSL and 587 for TSL.
- Encryption – You should always use encryption. Choose it to match the port number you use.
- Authentication – Select On because SMTP authentication needs to be enabled.
- Username – Your Gmail address.
- Password – The Gmail app password you created in the previous step.
If you code wordpress, throw this code in functions.php
add_action( 'phpmailer_init', function( $phpmailer ) { if ( !is_object( $phpmailer ) ) $phpmailer = (object) $phpmailer; $phpmailer->Mailer = 'smtp'; $phpmailer->Host = 'smtp.gmail.com'; $phpmailer->SMTPAuth = 1; $phpmailer->Port = 465; $phpmailer->Username = 'web888@gmail.com'; $phpmailer->Password = 'matkhauungdung'; $phpmailer->SMTPSecure = 'SSL'; $phpmailer->From = 'trienkhaiweb@gmail.com'; $phpmailer->FromName = 'Web888 - web888.vn'; });
If you use laravel, configure this parameter in .env . file
MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=465 MAIL_USERNAME=web888@gmail.com MAIL_PASSWORD=matkhauungdung MAIL_ENCRYPTION=null
For pure PHP websites or codeinigter, setting parameters for the mail server with the same configuration as above, the framework's functions, cms are all based on php mail , you learn how to configure each framework.
Good luck !