Copy all the file directories under zendframeLib to the org directory of thinkphp. (ThinkPHP \ Extend \ Library \ ORG \) this is the directory path of thinkphp3.0. Other versions may be different. Then write a script to change the file suffix from. php to. class. php.
To use the zendframe mail function in the thinkphp framework, record the operation procedure as follows:
Copy all the file directories under zendframe Lib to the org directory of thinkphp (ThinkPHP \ Extend \ Library \ ORG \). This is the directory path of thinkphp3.0. Other versions may be different. Then write a script to change the file suffix from. php to. class. php.
Then you can call thinkphp. add 'app _ AUTOLOAD_PATH '=> 'org' to the PHP file (custom search path ). However, this is not complete because the zend class name cannot be mapped to the corresponding file path in the autoload method of thinkphp, you have to modify the autoload method of thinkphp (use the underline in the class name to separate the assembly path ). At the same time, modify the import function (because the import function will automatically treat the string of the last segment as the class name)
Then, you can use the zend_mail class that I want to use. the code is given below.
Prompt: In the past, I thought that tp's autoload implementation was not good. First, it could not be extended, and it could not be searched for subdirectories.
- Autoload // shi_mody
- $ ClassPart = explode ('_', $ class );
- $ Class2 = implode ('.', $ classPart );
- // Shi_mody end
- Foreach ($ paths as $ path ){
- // Var_dump ($ path. '.'. $ class2 );
- If (import ($ path. '.'. $ class2) // shi_mody: $ class => $ class2
- // If the class is successfully loaded, return
- Return;
- }
Import function:
- If (strpos ($ class, 'org/zend') = 0 ){
- $ Classname = preg_replace ('//', '_', substr ($ class, 4 ));
- } Else {
- $ Classname = basename ($ class );
- }
- If (! Class_exists ($ classname, false )){
- // If the class does not exist, import the class library file
- Return require_cache ($ classfile );
- }
Script for file name change:
- $ Dir = "Validate /";
- TraceDir ($ dir, "reClass ");
- Function reClass ($ file ){
- If (strpos ($ file, "class. php ")){
- $ NFile = preg_replace ('/\. php/', "class. php", $ file); // Remember that the filename suffix meets the conditions
- Rename ($ file, $ nFile );
- }
- }
- Function traceDir ($ dir, $ callback ){
- $ H = opendir ($ dir );
- While ($ file = readdir ($ h ))){
- If ($ file = "." | $ file = "..")
- Continue;
- If (is_dir ($ dir. $ file )){
- TraceDir ($ dir. $ file. "/", $ callback );
- } Else {
- Call_user_func_array ($ callback, array ($ dir. $ file ));
- }
- }
- }
Call zend_mail:
- Class RssAction extends BaseAction {
- Public function send (){
- $ Email = addslashes ($ _ POST ['email ']);
- $ Title = addslashes ($ _ POST ['title']);
- $ Cont = $ _ POST ['cont'];
- // Import ("ORG. zend. mail "); // You do not need to import it here. In addition, the default zend class library in the tp framework is placed in ThinkPHP \ Extend \. if you use the default tp method, import is required in advance. at this time, if other class names are referenced in the class file, a large series of classes need to be imported.
- $ Smtp = new Zend_Mail ();
- $ Host = "smtp.qq.com ";
- $ Config = array (
- "Port" => 25,
- "Auth" => "Login ",
- "Username" => "werwer@qq.com ",
- "Password" => "werwer23"
- );
- Try {
- $ SmtpTrans = new Zend_Mail_Transport_Smtp ($ host, $ config );
- $ Mail = new Zend_Mail ();
- $ Mail-> setDefaultTransport ($ smtpTrans );
- $ Mail-> setBodyHtml ($ cont );
- $ Mail-> setFrom ($ config ["username"], "kindlerss.net ")
- -> AddTo ($ email, $ email)
- -> SetSubject ($ title );
- $ Mail-> send ();
- } Catch (Exception $ ex ){
- Echo $ ex-> message;
- }
- }
- }