文件下载
Yii::$app->response->sendFile(
"F://form.doc")->send();
邮件服务器配置:
//以aliyun企业邮为例,在config/web.phpd的
'components'里面配置
'urlManager' => [
....
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file
by default. You have to set
// 'useFileTransport' to
false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.mxhichina.com',
'username' => 'support@XXX.com',
'password' => 'XXX',
'port' => '25',
'encryption' => 'tls',
],
'messageConfig'=>[
'charset'=>'UTF-8',
'from'=>[
'support@XXX.com'=>'发送人']
],
],
邮件发送代码
date_default_timezone_
set(
'PRC');
$mail= Yii::
$app->mailer->compose();
$mail->
setTo(
"XXX@qq.com");
$mail->
setSubject(
"邮件测试");
//
$mail->attach(
'F:\\form.doc'); //发送附件方法
1
//
$mail->attachContent(
'Attachment content', [
'fileName' =>
'attach.txt',
'contentType' =>
'text/plain']); // 发送附件方法
2
//
$mail->
setTextBody(
'zheshisha '); //发布纯文字文本
$mail->
setHtmlBody(
"<br>问我我我我我"); //发布可以带html标签的文本
if(
$mail->send())
return true;
return false;
UrlManager 路由美化
/* 以下配置可以分别通过
/index
/模块名/controllerName
来访问,如localhost/web/index或localhost/index(取决于你的yii2 web目录的位置)
还有,可以配置extraPatterns 来调用你的自定义action
如
[
'class' => 'yii\rest\UrlRule',
'pluralize' => false,
'controller' => [
'v1/user'],
'extraPatterns' => [
'GET downloadform' => 'downloadform',
],
],
*/
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
[
'class' => 'yii\rest\UrlRule',
'pluralize' => false,
'controller' =>[
'index' => 'site',
'模块名/controllerName',
],
],
]
]
转载请注明原文地址: https://ju.6miu.com/read-1123337.html