Some time ago, the company has some statements of the task, there is no fault if the realization of an automatic day or month to send statements to the specified mailbox is indeed a great thing, so that every day someone to let you check the data, bitter, forced, class, trouble.
The pits where Laravel frame sent the mail are recorded below, hoping to help apes with the same development needs to avoid repeated pit falls.
1.1 Laravel Configuration files involved in Sending Emails
.env
/config/mail.phpCopy the code
The following is an example of how laravel can create a composer:
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=nullCopy the code
If you deploy mail.php and do not change the. Env configuration (unless you do not have a. Env), the email will not be sent successfully because the. Env file overwrites the mail.php field.
1.2 Problem of Using QQ Mailbox SMTP to Send Emails
1.2.1 Enable the SMTP and IMAP functions of the QQ Mailbox
Before using this QQ email to send, you need to enable SMTP and IMAP email authorization function in the background of the email to send, otherwise you will always be reminded that you are not authorized. Set the position directly above:
At least you need to have POP3/SMTP enabled, otherwise it’s impossible to send email.
Once enabled, you also need to click “Generate authorization code” below to obtain a dynamic password for login:
Please remember that MAIL_PASSWORD is not the account password for sending email, but the dynamic password authorized by Tencent email management Center!!
The encryption mode is recommended to select SSL to ensure data security, so eventually. Env email looks like this:
MAIL_DRIVER= SMTP MAIL_HOST=smtp.qq.com MAIL_PORT=465 MAIL_USERNAME=[your account] MAIL_PASSWORD=gzoyimtltnqsbdba MAIL_ENCRYPTION=sslCopy the code
In the mail.php configuration file, you only need to modify the FROM field:
Return [' from '= > [' address' = > [MAIL_USERNAME], 'name' = > 'wang']]Copy the code
Then you can email happily:
5.2 Email Sending Mode
\Mail::send('mail.index', [], function ($message) {$message->to(['[email protected]'])->subject(' number of unmarried.index '); });Copy the code
Since 5.3, sending emails has been abstracted into an object. If you are using Laravel 5.3, please check out the latest official documentation: laravel.com/docs/5.3/ma…