当前位置:网站首页>TP5 email (2020-05-27)
TP5 email (2020-05-27)
2022-04-23 03:03:00 【Stupid little attendant】
1、 Email opening SMTP service
2、git Download extensions phpmailer
https://github.com/PHPMailer/PHPMailer
Put in TP vendor Under the table of contents ( Mainly PHPMailer.php and SMTP.php Two documents )
- Be careful :PHPMailer.php and SMTP.php The namespace of the file must be
2、common.php Create a public method for sending mail
1) First use
2) Send mail method code
function sendEmail($data = [])
{
// Introduce these two lines , Otherwise, the report will be wrong
Vendor('phpmailer.PHPMailer');
Vendor('phpmailer.SMTP');
$mail = new PHPMailer(); // Instantiation
$mail->IsSMTP(); // Enable SMTP
$mail->Host = 'smtp.qq.com'; //SMTP The server With 126 Mailbox is an example
$mail->Port = 465; // Mail port
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->SMTPSecure = "ssl"; // Set the security verification method to ssl
$mail->CharSet = "UTF-8"; // Character set
$mail->Encoding = "base64"; // Encoding mode
$mail->Username = '[email protected]'; // Your email
$mail->Password = 'xxxxxxxxxxx'; // You open SMTP Service password
$mail->Subject = 'xxxx'; // Email title
$mail->From = '[email protected]'; // sender address ( Your email address )
$mail->FromName = ' petty thief '; // Sender's name
if ($data && is_array($data)) {
foreach ($data as $k => $v) {
$mail->AddAddress($v['user_email'], " nickname "); // Add recipient ( Address , nickname )
$mail->IsHTML(true); // Support html Format content
$mail->Body = $v['content']; // The main content of the mail
// Delete after sending successfully
if ($mail->Send()) {
echo " Send successfully ";
} else {
echo "Mailer Error: " . $mail->ErrorInfo; // Output error message
}
}
}
}
3、 The controller layer uses
// User registration sends email verification code
public function sendMailCode()
{
// User mailbox
$userMail = input('userMail','');
// Randomly generate customer code ,8 position
$chars = "0123456789";
$length = 6;
$vipCode = '';
for($i = 0; $i < $length; $i++){
$vipCode .= $chars{
mt_rand(0,9)};
}
// Store the verification code in session
Session::set('validate',$vipCode);
sendEmail([['user_email'=>$userMail, 'content'=>'【 Verification Code :( Please be there. 2 Fill in... In minutes )】' . $vipCode]]);
return json(['code' => 0, 'msg' => ' The verification code was obtained successfully ']);
}
版权声明
本文为[Stupid little attendant]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220630238649.html
边栏推荐
- Redis data server / database / cache (2022)
- Publish to NPM?
- Some problems encountered in setting Django pure interface, channel and MySQL on the pagoda panel
- SQL statement - DDL
- 一套关于 内存对齐 的C#面试题,做错的人很多!
- Restart redis
- Source Generator实战
- C#语法糖空合并运算符【??】和空合并赋值运算符【 ??=】
- HLS / chisel practice CORDIC high performance computing complex square root
- Opencv fills the rectangle with a transparent color
猜你喜欢
Traversal of l2-006 tree (middle and later order determination binary tree & sequence traversal)
Array and collection types passed by openfeign parameters
JS learning notes
Error installing Mongo service 'mongodb server' on win10 failed to start
Q-Learning & Sarsa
Linux redis - redis database caching service
Kubernetes study notes
[software testing] understand the basic knowledge of software testing
AspNetCore配置多环境log4net配置文件
L2-006 樹的遍曆(中後序確定二叉樹&層序遍曆)
随机推荐
Openfeign timeout setting
Reverse a linked list < difficulty coefficient >
《信息系统项目管理师总结》第七章 项目沟通管理
Distributed system services
Publish to NPM?
腾讯视频VIP会员,周卡特价9元!腾讯官方直充,会员立即生效!
Configuring Apache Web services for servers such as Tianyi cloud
Development notes of raspberry pie (12): start Advantech industrial control raspberry pie uno-220 Kit (I): introduction and operation of the system
c#语法糖模式匹配【switch 表达式】
腾讯视频涨价:一年多赚74亿!关注我领取腾讯VIP会员,周卡低至7元
Depth deterministic strategy gradient (ddpg)
《信息系統項目管理師總結》第六章 項目人力資源管理
FileNotFoundError: [Errno 2] No such file or directory
Traversée de l'arbre L2 - 006
AOT和单文件发布对程序性能的影响
Winsock programming interface experiment: implementation of ipconfig
Redis data server / database / cache (2022)
Deep q-network (dqn)
Detailed log display of openfeign call
ASP.NET 6 中间件系列 - 条件中间件