当前位置:网站首页>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
边栏推荐
- ele之Table表格的封装
- HLS / chisel practice CORDIC high performance computing complex square root
- C#中切片语法糖的使用
- Detailed explanation of distributed things
- Reverse a linked list < difficulty coefficient >
- Encapsulation of ele table
- Introduction and use of openfeign component
- tf. keras. layers. Conv? D function
- Chapter V project quality management of information system project manager summary
- 腾讯视频涨价:一年多赚74亿!关注我领取腾讯VIP会员,周卡低至7元
猜你喜欢

Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (8)

Sonic cloud real machine tutorial

HLS / chisel practice CORDIC high performance computing complex square root

最通俗易懂的依赖注入之生命周期

樹莓派開發筆記(十二):入手研華ADVANTECH工控樹莓派UNO-220套件(一):介紹和運行系統

C# WPF UI框架MahApps切换主题

Cloud computing learning 1 - openstack cloud computing installation and deployment steps with pictures and texts (Xiandian 2.2)

C#中切片语法糖的使用
![Introduction to ACM [inclusion exclusion theorem]](/img/3a/9bc2a972d7587aab51fceb8cd2b9bd.png)
Introduction to ACM [inclusion exclusion theorem]

Source Generator实战
随机推荐
AC380V drop 5v12v24v200ma, UHV non isolated chip IC scheme
Kubernetes - detailed explanation of pod
基于ele封装下拉菜单等组件
Openfeign service call
MYSQL_ From mastery to abandonment
Summary of software test interview questions
C# WPF UI框架MahApps切换主题
tf. keras. layers. MaxPooling? D function
Reverse a linked list < difficulty coefficient >
Configuring Apache Web services for servers such as Tianyi cloud
Deep q-network (dqn)
Openfeign details show
How to use C language to realize [guessing numbers game]
How to deploy a website with only a server and no domain name?
ASP.NET 6 中间件系列 - 自定义中间件类
ASP.NET 6 中间件系列 - 执行顺序
JSON data text
SQL statement - DDL
Table space capacity query and expansion of Oracle Database
L2-006 樹的遍曆(中後序確定二叉樹&層序遍曆)