This article describes the method of thinkingphp to realize the function of sending email password recovery. Share it for your reference. The specific implementation method is as follows:
First download the class file and define the following parameters in the configuration file:
Copy the codeThe code is as follows:
'MAIL_ADDRESS' => 'ivzhu@', // Email address
'MAIL_SMTP' => '', // Mailbox SMTP server
'MAIL_LOGINNAME' => 'mail@', // Email login account
'MAIL_PASSWORD' => '123456', // Email Password
'MAIL_CHARSET' => 'UTF-8', // Encoding
'MAIL_AUTH' => true, // Email authentication
'MAIL_HTML' => true, // true HTML format false TXT format
'MAIL_SMTP' => '', // Mailbox SMTP server
'MAIL_LOGINNAME' => 'mail@', // Email login account
'MAIL_PASSWORD' => '123456', // Email Password
'MAIL_CHARSET' => 'UTF-8', // Encoding
'MAIL_AUTH' => true, // Email authentication
'MAIL_HTML' => true, // true HTML format false TXT format
Put it in the tp project org, and import('@.');
Copy the codeThe code is as follows:
public function index(){
import('@.');
//SendMail('admin@','mail title','mail text','waiku CMS administrator');
//Explanation parameters: Parameter 1---target mailbox, Parameter 2----mail title, Parameter 3--mail text, Parameter 4---sender name;
$content=md5(time());
session($content,$content);
$content=C('localurl').'/'.U('Mail/index',array('res'=>$content));
if(SendMail('aa@','nihao email title',$content,'unphp')){
echo 'chengong';
}else{
echo 'shibai';
}
$this->display();
}
import('@.');
//SendMail('admin@','mail title','mail text','waiku CMS administrator');
//Explanation parameters: Parameter 1---target mailbox, Parameter 2----mail title, Parameter 3--mail text, Parameter 4---sender name;
$content=md5(time());
session($content,$content);
$content=C('localurl').'/'.U('Mail/index',array('res'=>$content));
if(SendMail('aa@','nihao email title',$content,'unphp')){
echo 'chengong';
}else{
echo 'shibai';
}
$this->display();
}
Another page accepts parameter res:
Copy the codeThe code is as follows:
public function index(){
header("Content-type: text/html; charset=utf-8");
$res=I('res');
echo $res;
if(session($res)==$res){
echo 'Password retrieval was successful';
session($res,null);
}else{
echo 'has expired';
}
}
header("Content-type: text/html; charset=utf-8");
$res=I('res');
echo $res;
if(session($res)==$res){
echo 'Password retrieval was successful';
session($res,null);
}else{
echo 'has expired';
}
}
I hope this article will be helpful to everyone's ThinkPHP framework programming.