Summary of sending emails using the Laravel framework

Source: Internet
Author: User
Tags imap php file php and

Some time ago, the company has a report of the task, it is understandable if the implementation of an automatic by day or monthly report sent to the designated mailbox is really a cool thing, so that every day someone to let you check the data, bitter, forced, class, annoying.

The following is a record of the pits where the laravel frame sends the mail, hoping to help apes with the same development needs to avoid repeating the pits.

1.1 Laravel The configuration files involved in sending mail

. env
/config/mail.php

The above is the Laravel send the mail two configuration place, by default uses composer to build the project, the automatic generation. env file will have the Mailbox configuration field, as follows:

Mail_driver=smtp
Mail_host=mailtrap.io
mail_port=2525
Mail_username=null
Mail_password=null
Mail_encryption=null

The above several fields in the mail.php file have the corresponding fields, if the deployment of the online, only configured mail.php and did not change the configuration in the Env file (unless No. env), then the mailbox is sent unsuccessfully because the. env file overwrites the mail.php file field, remember to be careful.

1.2 Use QQ mailbox SMTP Send mail question

1.2.1 Open QQ mailbox SMTP and IMAP function

In the use of this QQ email before you need to send the mailbox in the background to open SMTP and IMAP send mailbox authorization function, otherwise you will always be prompted not to authorize. Set the location directly above the figure:

Ps://dailyios.oss-cn-shenzhen.aliyuncs.com/86270abfdc3fd1f5e21c.jpg "/>

At least you need to open the POP3/SMTP service, or email it is impossible.

After opening, you also need to click the following: "Generate authorization Code", get a dynamic password to log in:

Chivan remembers, Mail_password fills in not is sends the mailbox the account password, but to Tencent Mailbox Management Center authorizes the dynamic password!!!

Encryption recommended that you choose to choose SSL to ensure data security, then ultimately. env message length is this:

Mail_driver=smtp
Mail_host=smtp.qq.com
mail_port=465
Mail_username=[your account number]
Mail_password=gzoyimtltnqsbdba
Mail_encryption=ssl
mail.php configuration file, you just need to modify the From field:

return [
' From ' => [' address ' => [mail_username], ' name ' => ' Xiao Wang ']
]

And then you can have a nice big email:

5.2 Ways to send mail
\mail::send (' Mail.index ', [], function ($message) {$message->to ([' chengxuyuan@qq.com '])->subject (' Company number of unmarried sister statistics ');
Starting from 5.3, sending mail is abstracted into an object, if using Laravel 5.3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.