


The following tutorial column of thinkphp framework will introduce to you how the ThinkPHP framework implements the email activation function. I hope it will be helpful to friends in need!
The details are as follows:
The configuration framework adopts the ThinkPHP3.1 framework, as shown below:
Configuration process diagram:
1. Modify the configuration as follows:
<?php return array( //'配置项'=>'配置值' 'MAIL_ADDRESS'=>'shcg666@sohu.com', // 邮箱地址 'MAIL_SMTP'=>'smtp.sohu.com', // 邮箱SMTP服务器 'MAIL_LOGINNAME'=>'shcg666@sohu.com', // 邮箱登录帐号 'MAIL_PASSWORD'=>'******', // 邮箱密码 );
2. Add a class to the function
<?php class EmailAction extends Action{ /* * microtime() 函数返回当前 Unix 时间戳和微秒数。 * mt_srand() 播种 Mersenne Twister 随机数生成器。从 PHP 4.2.0 版开始,seed 参数变为可选项,当该项为空时,会被设为随时数。 * 注释:自 PHP 4.2.0 起,不再需要用 srand() 或 mt_srand() 函数给随机数发生器播种,现已自动完成。 * pow — 指数表达式 */ //random()这个函数是我用来生成一个随机数的,$numeric = 0生成一个6位的大小写字母与数字混合的字符串。$numeric = 1生成一个6位数字的字符串 public function random($length = 6 , $numeric = 0) { PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000); if($numeric) { $hash = sprintf('%0'.$length.'d', mt_rand(0, pow(10, $length) - 1)); } else { $hash = ''; $chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789abcdefghjkmnpqrstuvwxyz'; $max = strlen($chars) - 1; for($i = 0; $i < $length; $i++) { $hash .= $chars[mt_rand(0, $max)]; } } return $hash; } //发送邮件的方法 public function index(){ //生成6位激活码 $random = $this->random(6,0); //获取本网站的域名,域名在config里面配置下. //例如'domain' => 'http://write.blog.csdn.net', $domain = C('domain'); //生成激活码模块地址 $url = $domain.U("Home/Email/activate")."/?yam=$random"; //将邮件地址和随机数放入session session("shcg666@sohu.com","$random"); //发送邮件 SendMail("shcg666@sohu.com","这是邮件标题","将此网址复制到浏览框$url"); } } function SendMail($address,$title,$message){ //引入文件 vendor('PHPMailer.class#PHPMailer'); require("phpmailer/class.phpmailer.php"); require("phpmailer/class.smtp.php"); //实例化邮件类 $mail=new PHPMailer(); // 设置PHPMailer使用SMTP服务器发送Email $mail->IsSMTP(); // 设置邮件的字符编码,若不指定,则为'UTF-8' $mail->CharSet='UTF-8'; // 添加收件人地址,可以多次使用来添加多个收件人 $mail->AddAddress($address); // 设置邮件正文 $mail->Body=$message; // 设置邮件头的From字段。//发件人 $mail->From=C('MAIL_ADDRESS'); // 设置发件人名字 $mail->FromName='LilyRecruit'; // 设置邮件标题 $mail->Subject=$title; // 设置SMTP服务器。 $mail->Host=C('MAIL_SMTP'); // 设置为"需要验证" $mail->SMTPAuth=true; // 设置用户名和密码。 $mail->Username=C('MAIL_LOGINNAME'); $mail->Password=C('MAIL_PASSWORD'); // 发送邮件。 return($mail->Send()); }
3. Imported files
Download the PHPMailer package from the Internet and copy class.smtp.php and class.phpmailer.php directly without any changes.
Click the link to download the class.smtp.php file (https://share.weiyun.com/6ECQn7Mq).
For the complete example code of class.phpmailer.php file, click the link to download (https://share.weiyun.com/beakkcPt) .
Configuration is complete, the specific processing method needs further changes.
4. Common mail server (receiving server and sending mail server) addresses
Tencent QQ mailbox
Receiving server: pop.qq.com
Sending Server: smtp.qq.com
Netease 126 mailbox
Receiving server: pop3.126.com
Sending server: smtp.126.com
Netease 163 free mail
Receiving server: pop.163.com
Sending server: smtp.163.com
NetEase 163VIP mailbox
Receiving server: pop.vip.163.com
Sending server: smtp. vip.163.com
NetEase 188 Fortune Mail
Receive server: pop.188.com
Send server: smtp.188.com
NetEase yeah.net mailbox
Receiving server: pop.yeah.net
Sending server: smtp.yeah.net
Netease netease.com mailbox
Receiving server: pop.netease.com
Sending server: smtp. netease.com
Sina paid mailbox
Receiving server: pop3.vip.sina.com
Sending server: smtp.vip.sina.com
Sina free mailbox
Receiving server: pop3.sina.com.cn
Sending server: smtp.sina.com.cn
Sohu Mailbox
Receiving server: pop3.sohu.com
Sending server: smtp. sohu.com
21cnhappymail
Receive server: vip.21cn.com
Sending server: vip.21cn.com
21cn Economic Mail
Receive server: pop .163.com
Sending server: smtp.163.com
tom mailbox
Receiving server: pop.tom.com
Sending server: smtp.tom.com
263mailbox
Receive server: 263.net
Send server: smtp.263.net
NetEase 163.com mailbox
Receive server: rwypop.china.com
Send server :rwypop.china.com
Yahoo mailbox
Receiving server: pop.mail.yahoo.com
Sending server: smtp.mail.yahoo.com
Gmail mailbox
Receive server: pop.gmail.com
Sending server: smtp.gmail.com
Related recommendations:The latest 10 thinkphp video tutorials
The above is the detailed content of Detailed explanation of how the ThinkPHP framework implements email activation function. For more information, please follow other related articles on the PHP Chinese website!

thinkphp是国产框架。ThinkPHP是一个快速、兼容而且简单的轻量级国产PHP开发框架,是为了简化企业级应用开发和敏捷WEB应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。

本篇文章给大家带来了关于thinkphp的相关知识,其中主要介绍了关于使用think-queue来实现普通队列和延迟队列的相关内容,think-queue是thinkphp官方提供的一个消息队列服务,下面一起来看一下,希望对大家有帮助。

thinkphp基于的mvc分别是指:1、m是model的缩写,表示模型,用于数据处理;2、v是view的缩写,表示视图,由View类和模板文件组成;3、c是controller的缩写,表示控制器,用于逻辑处理。mvc设计模式是一种编程思想,是一种将应用程序的逻辑层和表现层进行分离的方法。

本篇文章给大家带来了关于thinkphp的相关知识,其中主要介绍了使用jwt认证的问题,下面一起来看一下,希望对大家有帮助。

thinkphp扩展有:1、think-migration,是一种数据库迁移工具;2、think-orm,是一种ORM类库扩展;3、think-oracle,是一种Oracle驱动扩展;4、think-mongo,一种MongoDb扩展;5、think-soar,一种SQL语句优化扩展;6、porter,一种数据库管理工具;7、tp-jwt-auth,一个jwt身份验证扩展包。

本篇文章给大家带来了关于ThinkPHP的相关知识,其中主要整理了使用think-queue实现redis消息队列的相关问题,下面一起来看一下,希望对大家有帮助。

thinkphp查询库是否存在的方法:1、打开相应的tp文件;2、通过“ $isTable=db()->query('SHOW TABLES LIKE '."'".$data['table_name']."'");if($isTable){...}else{...}”方式验证表是否存在即可。

在thinkphp3.2中,可以利用define关闭调试模式,该标签用于变量和常量的定义,将入口文件中定义调试模式设为FALSE即可,语法为“define('APP_DEBUG', false);”;开启调试模式将参数值设置为true即可。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.