Code to send SMTP email from Gmail for WordPress

Code to send SMTP email from Gmail for WordPress

WordPress users are no longer unfamiliar with the SMTP email sending function, Code to send SMTP email from Gmail right? Normally, WordPress needs an email server to send content from the website to the admin email address, or to the email address of the recipient of the notification, for example sending the user’s contact form to the admin. website, email confirmation of password change…etc.

Code to send SMTP email from Gmail for WordPress

Code gửi email SMTP

Copy the code below and paste it into the functions.php file of the theme you are using.

  1. // tu dong gui email
  2. add_action( ‘phpmailer_init’, function( $phpmailer ) {
  3. if ( !is_object( $phpmailer ) )
  4. $phpmailer = (object) $phpmailer;
  5. $phpmailer->Mailer = ‘smtp’;
  6. $phpmailer->Host = ‘smtp.gmail.com’;
  7. $phpmailer->SMTPAuth = 1;
  8. $phpmailer->Port = 587;
  9. $phpmailer->Username = ‘Account’;
  10. $phpmailer->Password = ‘Application Password’;
  11. $phpmailer->SMTPSecure = ‘TLS’;
  12. $phpmailer->From = ‘Send email address’;
  13. $phpmailer->FromName = ‘Sender Name’;
  14. });
  15. // set the user’s email address

 

Notice to change the following contents:
‘Account’ replace with your gmail account.
‘App password’ how to get the app password see below.
‘Send email address’ replaces the email address to send in.
‘Sender Name’ replace the name you want to enter.

 

How to get app password

Click on the link below then log into your Gmail account.
https://myaccount.google.com/u/1/security

Code to send SMTP email from Gmail for WordPress
Code to send SMTP email from Gmail for WordPress

Select 2-Step Verification.

Code to send SMTP email from Gmail for WordPress
Code to send SMTP email from Gmail for WordPress

Select Confirm code via text message , after confirming and enabling 2-layer security, return to the account security section.

Code to send SMTP email from Gmail for WordPress
Code to send SMTP email from Gmail for WordPress

Continue to select the item App password.

Code to send SMTP email from Gmail for WordPress
Code to send SMTP email from Gmail for WordPress

Select Other app (Optional Name).

Code to send SMTP email from Gmail for WordPress
Code to send SMTP email from Gmail for WordPress

Name the application, you can give it whatever you want.

Code to send SMTP email from Gmail for WordPress
Code to send SMTP email from Gmail for WordPress

Well, finally, our application password is displayed. Copy this app password and paste it in the code above.

Note: With this method, the mail sent will never be in the spam folder. However, Gmail limits us to only sending a maximum of 100 messages per day and if we exceed the number of messages, we will send them 24 hours later.

5/5 - (4 bình chọn)

Trả lời

Email của bạn sẽ không được hiển thị công khai.

Gọi ngay

Facebook Chat

Zalo Chat