Configuration
The configuration file for the message is in the config/mail.php file, and the configuration entry and description are as follows:
<?php
return [
/*
|--------------------------------------------------------------------------
| Mail Driver
|--------------------------------------------------------------------------
|
| Laravel supports both SMTP and PHP ' mail ' function as drivers for the
| Sending of e-mail. You may specify which one ' re using throughout
| Your application here. By default, Laravel are setup for SMTP Mail.
|
| Supported: "SMTP", "Mail", "SendMail", "Mailgun", "Mandrill",
| "ses", "sparkpost", "Log"
|
*/
SMTP driver is used by default, support "SMTP", "Mail", "SendMail", "Mailgun", "Mandrill", "ses", "sparkpost", "Log"
' Driver ' => env (' Mail_driver ', ' SMTP '),
/*
|--------------------------------------------------------------------------
| SMTP Host Address
|--------------------------------------------------------------------------
|
| This is provide the host address of the SMTP server used by your
| Applications. A default option is provided this is compatible with
| The Mailgun Mail Service which'll provide reliable deliveries.
|
*/
Host address of SMTP server
' Host ' => env (' mail_host ', ' smtp.mailgun.org '),
/*
|--------------------------------------------------------------------------
| SMTP Host Port
|--------------------------------------------------------------------------
|
| This is the SMTP port used by your application to deliver e-mails to
| Users of the application. Like the host we have set this value to
| Stay compatible with the Mailgun e-mail application by default.
|
*/
Port
' Port ' => env (' Mail_port ', 587),
/*
|--------------------------------------------------------------------------
| Global ' from ' address
|--------------------------------------------------------------------------
|
| You could wish for all e-mails sent by your application to is sent from
| The same address. Here, your may specify a name and address this is
| Used globally for all e-mails this are sent by your application.
|
*/
Configure the global Send mailbox address and name
' From ' => [' Address ' => ' json_vip@163.com ', ' name ' => ' Mayanlong personal blog '],
/*
|--------------------------------------------------------------------------
| e-Mail Encryption Protocol
|--------------------------------------------------------------------------
|
| This is the Specify the encryption protocol that should being used when
| The application send e-mail messages. A sensible Default using the
| Transport Layer Security protocol should provide great.
|
*/
Agreement
' Encryption ' => env (' mail_encryption ', ' TLS '),
/*
|--------------------------------------------------------------------------
| SMTP Server Username
|--------------------------------------------------------------------------
|
| If your SMTP server requires a username for authentication, your should
| Set it here. This'll get used to authenticate with your server on
| Connection. You may also set the "password" value below this one.
|
*/
Send email account
' Username ' => env (' Mail_username '),
/*
|--------------------------------------------------------------------------
| SMTP Server Password
|--------------------------------------------------------------------------
|
| This is the password required by your SMTP server to send out
| Messages from your application. This is given to the server on
| Connection so the application would be able to send messages.
|
*/
Send mailbox password
' Password ' => env (' Mail_password '),
/*
|--------------------------------------------------------------------------
| Sendmail System Path
|--------------------------------------------------------------------------
|
| When using the ' SendMail ' driver to send e-mails, we'll need to know
| The path to where Sendmail lives in this server. A Default Path has
| been provided here, which'll work down on most of your systems.
|
*/
' SendMail ' => '/usr/sbin/sendmail-bs ',
];
The specific parameter values are configured in the. env file, which uses the 163 mailbox SMTP service, configured as follows:
Mail_driver=smtp
Mail_host=smtp.163.com
mail_port=465
Mail_username=json_vip@163.com
mail_password= the corresponding account password
Mail_encryption=ssl
Third, send mail
Remember to use Mail when using;
1. Send Plain text message
$num = Mail::raw (' Mail content ', function ($message) {
$message->from (' json_vip@163.com ', ' Name of Sender ');
$message->subject (' mail subject ');
$message->to (' 849291170@qq.com ');
});
2. Send HTML view
Using the welcome template in the mails directory, the passed parameters are used to assign values to the variables in the template:
$num = Mail::send (' Mails.welcome ', [' Name ' => ' Sean '], function ($message) {
$message->to (' 849291170@qq.com ');
});
The corresponding template is: