使用 “阿里云邮件推送” 发送邮件:
前提: “阿里云邮件推送” 已配置好了!这里粘帖出我的配置
方式一 SMTP模式
Laravel 5.0
以上都可以使用!
1. 修改.env
配置文件中MAIL部分
# Mail: smtp
MAIL_DRIVER=smtp
# Aliyun mail
MAIL_HOST=smtpdm.aliyun.com
MAIL_PORT=465
MAIL_USERNAME=[你的发信地址]
MAIL_PASSWORD=[你设置的SMTP密码]
MAIL_ENCRYPTION=ssl
2. 修改config/mail.php
配置
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => [
'address' => 'nst@mail.51nst.net',
'name' => '纽斯特文化科技',
],
3. 发送邮件
$to = '469306621@qq.com';
$subject = '用户注册通知';
Mail::raw('用户注册通知: This is test', function ($msg) use ($to, $subject) {
$msg->to($to);
$msg->subject($subject);
});
4. 结果
方式二 SDK模式
要求Laravel 5.5
以上才可以使用。
使用:https://github.com/HyanCat/aliyun-direct-mail 这个包来完成阿里云邮件推送.
1. 安装
composer require hyancat/aliyun-direct-mail:dev-master
2. 修改 config/app.php
文件,在 providers
字段中添加
'providers' => [
...
HyanCat\DirectMail\AliyunDirectMailServiceProvider::class,
...
],
3. 修改config/services.php
增加如下配置
'directmail' => [
'app_key' => env('DIRECT_MAIL_APP_KEY'),
'app_secret' => env('DIRECT_MAIL_APP_SECRET'),
'region' => env('DIRECT_MAIL_REGION'),
'account' => [
'alias' => env('DIRECT_MAIL_ACCOUNT_ALIAS'),
'name' => env('DIRECT_MAIL_ACCOUNT_NAME'),
]
],
4. 修改.env
配置文件中MAIL部分
# Mail: directmail
MAIL_DRIVER=directmail
# AliYun directmail
DIRECT_MAIL_APP_KEY=[你的appKey]
DIRECT_MAIL_APP_SECRET=[你的appSecret]
DIRECT_MAIL_ACCOUNT_ALIAS=[你的发信域名]
DIRECT_MAIL_ACCOUNT_NAME=[你的发信地址]
DIRECT_MAIL_REGION=cn-hangzhou
5. 发送邮件
$to = '469306621@qq.com';
$subject = '用户注册通知';
Mail::raw('用户注册通知: This is test', function ($msg) use ($to, $subject) {
$msg->to($to);
$msg->subject($subject);
});
6. 结果