Learn how to use email

We will send a welcome email when the user registers, like thinkPHP, we need to integrate the email to send, but laravel has already integrated the email to send, as long as we configure it, the following will show me some problems in the process of learning to send email.

First problem: unable to connect to mailbox 163

The following error message appears during the configuration process, as shown in the figure:

After careful check, I found that my port number and connected user name (I configured it without the suffix @163.com) were not correctly configured.

Second problem: Authorization code is not enabled

During the configuration process, the following error message often appears, as shown in the figure below:

The first step is to log in to email 163 to enable the authorization code function.

After this function is enabled, you need to configure the password in the env file. Set the password as: authorization code, not login password, authorization code, not login password.

Third question

We configured the error message in the previous configuration item, but after we configured the correct email configuration information, the original error message still exists, no matter how we modified it, as shown in the figure below:

My first impression is: This may be caused by cache files, but after using the PHP artisan config:clear command, I still get the same error message. At this time, I start to use Google search, but there is no specific solution. Finally, I remember that I forgot to restart the server: Restart the server, and after the restart, the results are normal. Configure a graph of the server on Stack Overflow that prompts you to restart:

conclusion

Learn how to use Laravel to send emails:

  1. The authorization code function must be enabled for the configured email sending function
  2. The MAIL_USERNAME in env must have the suffix @163.com
  3. In the mail. PHP file in the configuration folder, address and name must be configured for the key value of from. It is recommended to write the configuration item to env
  4. During the email sending configuration, the server must be restarted. Otherwise, any modification will not take effect