Home>Article>PHP Framework> Detailed explanation of how the ThinkPHP framework implements email activation function

Detailed explanation of how the ThinkPHP framework implements email activation function

藏色散人
藏色散人 forward
2021-06-11 12:00:04 3949browse

The following tutorial column ofthinkphp frameworkwill 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:

Detailed explanation of how the ThinkPHP framework implements email activation function

1. Modify the configuration as follows:

'配置值' '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

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 linkto download the class.smtp.php file (https://share.weiyun.com/6ECQn7Mq).

For the complete example code of class.phpmailer.php file, click the linkto 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!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete