In the Laravel framework, send email instances (email verification) and laravel sends emails
After a period of use, it is found that user verification is required in many areas of the project, and text message verification and email verification are the mainstream trends, this article briefly summarizes how to implement the mail sending function in the Laravel framework and how to implement text message verification in the future .....
Under the. env file
1. Configure the Laravel File
MAIL_DRIVER = smtp // we recommend that you use smtp.
MAIL_HOST = smtp.163.com // an error is reported when you use the 163 mailbox QQ mailbox.
MAIL_PORT = 25 // smtp is 25 by default
MAIL_USERNAME = null // your 163 account
MAIL_PASSWORD = null // client Password
MAIL_ENCRYPTION = null
2. Modify the config/email. php file
'From' => ['address' => null, 'name' => null], // No prompt is displayed in the manual, but in actual application, if it is addredd => null, an error is returned. You need to write your 163 address every day.
3. register the 163 mailbox and set the mailbox accountPOP3, SMTP, and IMAP must be enabled and the authorization code must be enabled for mobile phone verification.
4. Refer to the send email in Laravel manual.
Note that the use Mail must be referenced first when the Controller references the email to be sent.
Test email sending
Set in route
Write method in Controller
Where
1: Mail: raw is used to send native data, and other content Sending methods are provided in the Manual;
2. $ message-> subjuet (''); is the file title
3. $ message-> to (); sent
This is a copy$message
List of methods available in the message generator instance:
$ Message-> from ($ address, $ name = null); $ message-> sender ($ address, $ name = null); $ message-> to ($ address, $ name = null); $ message-> cc ($ address, $ name = null); $ message-> bcc ($ address, $ name = null ); $ message-> replyTo ($ address, $ name = null); $ message-> subject ($ subject); $ message-> priority ($ level ); $ message-> attach ($ pathToFile, array $ options = []); // append a file with the original $ data string... $ message-> attachData ($ data, $ name, array $ options = []); // gets the underlying SwiftMailer message instance... $ message-> getSwiftMessage ();