当前位置:网站首页>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
边栏推荐
- Plug in for vscode
- @Usage and difference between mapper and @ repository
- 腾讯视频涨价:一年多赚74亿!关注我领取腾讯VIP会员,周卡低至7元
- Introduction to ACM [TSP problem]
- Encapsulate components such as pull-down menu based on ele
- Publish to NPM?
- Introduction and use of openfeign component
- How to count the number of all files in a directory under win10 system
- Small companies don't make formal offers
- Reverse a linked list < difficulty coefficient >
猜你喜欢

Development notes of raspberry pie (12): start Advantech industrial control raspberry pie uno-220 Kit (I): introduction and operation of the system

Linux redis - redis database caching service

Blazor University (12)组件 — 组件生命周期

Huawei machine test question -- deformation of hj53 Yang Hui triangle

Kubernetes study notes

Shell script learning notes - regular expressions

MYSQL05_ Ordr by sorting, limit grouping, group by grouping

tf. keras. layers. Conv? D function
![How to use C language to realize [guessing numbers game]](/img/8c/052dcb0ce64ee1713bebb1340248e6.png)
How to use C language to realize [guessing numbers game]

Summary of interface automation interview questions for software testing
随机推荐
Cloud computing learning 1 - openstack cloud computing installation and deployment steps with pictures and texts (Xiandian 2.2)
Redis data server / database / cache (2022)
Gavl021, gavl281, AC220V to 5v200ma small volume non isolated chip scheme
The shell monitors the depth of the IBM MQ queue and scans it three times in 10s. When the depth value exceeds 5 for more than two times, the queue name and depth value are output.
Winsock programming interface experiment: implementation of ipconfig
MYSQL_ From mastery to abandonment
最通俗易懂的依赖注入之服务容器与作用域
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (9)
基于ele封装下拉菜单等组件
It turns out that PID was born in the struggle between Lao wangtou and Lao sky
Numpy append function
Niuke white moon race 5 [problem solving mathematics field]
FileNotFoundError: [Errno 2] No such file or directory
tf. keras. layers. Density function
c#语法糖模式匹配【switch 表达式】
Face longitude:
eventBus
Summary of software test interview questions
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (8)
@Usage and difference between mapper and @ repository