对称加密

1.打开main-local.php文件添加:

'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.sina.com', //每种邮箱的host配置不一样
'username' => 'gg24155@sina.com', //发件人邮箱
'password' => 'gghw4089225', //授权码
'port' => '25',
'encryption' => 'tls',
],
'messageConfig'=>[
'charset'=>'UTF-8',
'from'=>['gg24155@sina.com'=>'nickname'] //发件人昵称
],
],

2.控制器demo:

//对称加密+发送邮箱
public function actionEncrypt(){
header("Content-type:text/html;charset=utf-8");
$msg = "张三";
//$pwd = "123";
$re = Yii::$app->security->encryptByKey($msg,'');
$arr = urlencode($re);
$mail = Yii::$app->mailer->compose();
$mail->setTo('xxxxxxx@qq.com'); //接收人邮箱
$mail->setSubject("test"); //邮件标题
$mail->setHtmlBody("http://www.hanwei.com/day_exercise/frontend/web/index.php?r=test/get_email&name=".$arr); //发送内容(可写HTML代码)
if ($mail->send()){
echo "成功";
}else{
echo "失败";
}
}
//接受邮箱信息
public function actionGet_email(){
header("Content-type:text/html;charset=utf-8");
$re3 = urldecode($_GET['name']);
$re1 = Yii::$app->security->decryptByKey($re3,'');
echo $re1;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值