Home > Article > Backend Development > Implement sending email instance (email verification) in Laravel framework, laravel sends email_PHP tutorial
After using it for a period of time, I found that user verification is needed in many places in the project , with SMS verification and email verification as the mainstream trends, the editor of this article summarizes how to implement the email sending function in the Laravel framework. In the future, we will continue to update how to implement SMS verification....
Under the .env file
1. Configure Laravel file
MAIL_DRIVER=smtp //It is recommended to use smtp method
MAIL_HOST=smtp.163.com //It is recommended to use 163 mailbox and QQ mailbox will report an error
MAIL_PORT=25//smtp default is 25
MAIL_USERNAME=null //My own 163 account
MAIL_PASSWORD=null //Client password
MAIL_ENCRYPTION=null
2. Modify
in the config/email.php file'from' => ['address' => null, 'name' => null], //There is no prompt in the manual, but in actual application, if addredd=>null, an error will be reported, which will take days Write your own 163 address
3. Register 163’s email address and set up your email account Enable POP3/SMTP/IMAP and enable the authorization code and perform mobile phone verification
4. Refer to the Laravel manual for sending emails
It must be noted that when the controller quotes the email to send, it must first quote use Mail
Send email test
Set in routing
Writing methods in the controller
Among them
1:Mail::raw is used to send native data, other content sending methods are provided in the manual;
2.$message->subjuet(''); is the title of the file
3.$message->to();To whom to send
This is a list of methods that can be used in $message
message generator instances:
$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 = []); // 以原始 $data 字符串附加一个文件... $message->attachData($data, $name, array $options = []); // 获取底层的 SwiftMailer 消息实例... $message->getSwiftMessage();