Php 视图未按预期显示 私有函数sendmail($userid、$reportcontent、$email){ //如果($this->Session->read($this->\u用户名)) { $this->loadModel('EwtMailtemplate'); $this->loadModel('EwtUser'); $this->loadModel('EwtSetting'); $this->autoRender=false; $date=日期(“Y-m-d”); $userinfo=$this->EwtUser->read(null,$userid); $fullname=$userinfo['EwtUser']['fullname']; $lastname=$userinfo['EwtUser']['lastname']; $mailtemp=$userinfo['EwtUser']['mailtemp']; 如果($mailtemp==0){ $mailtemp=1; } $setting=$this->EwtSetting->find('first'); $mailhost=$setting['EwtSetting']['mailhost']; $mailuser=$setting['EwtSetting']['mailuser']; $mailpass=$setting['EwtSetting']['mailpass']; //$reportmail=$setting['EwtSetting']['reportmail']; $reportmail=$email; $bodymail=$this->EwtMailtemplate->read(null,$mailtemplate); //$header=$bodymail['EwtMailtemplate']['header']; //$footer=$bodymail['EwtMailtemplate']['footer']; //$title=$bodymail['EwtMailtemplate']['title']; $subject=“工作时间系统的新登录密码”; //$subject=$lastname.“.str_替换(“[date]”,$date,$title); //$header=str_replace(“[lastname]”,$lastname,$header); //$header=str_replace(“[date]”,$date,$header); //$footer=str_replace(“[lastname]”,$lastname,$footer); //$content=''.$header.'“$reportcontent.“$footer.”; $content='1 “.”“$reportcontent。”“; $this->Email->to=$reportmail; $this->Email->charset='UTF-8'; $this->Email->from=sprintf(“%s”,$fullname,$mailuser); $this->Email->replyto=sprintf(“%s”,$fullname,$mailuser); $this->Email->subject=$subject; $this->Email->sendAs='html'; $smtp=数组( “端口”=>25, “主机”=>$mailhost, “超时”=>99, “用户名”=>$mailuser, “密码”=>$mailpass ); $this->Email->smtpOptions=$smtp; $this->Email->delivery='smtp'; $bool=($this->Email->send($content))?true:false; $smtp_error=$this->Email->smtpError; 如果(strlen($smtp_错误)>0){ //$this->Session->setflash($smtp\u错误); $bool=false; } 如果(!$bool) { $this->redirect(数组('action'=>'userexists'); } 返回$bool; } }

Php 视图未按预期显示 私有函数sendmail($userid、$reportcontent、$email){ //如果($this->Session->read($this->\u用户名)) { $this->loadModel('EwtMailtemplate'); $this->loadModel('EwtUser'); $this->loadModel('EwtSetting'); $this->autoRender=false; $date=日期(“Y-m-d”); $userinfo=$this->EwtUser->read(null,$userid); $fullname=$userinfo['EwtUser']['fullname']; $lastname=$userinfo['EwtUser']['lastname']; $mailtemp=$userinfo['EwtUser']['mailtemp']; 如果($mailtemp==0){ $mailtemp=1; } $setting=$this->EwtSetting->find('first'); $mailhost=$setting['EwtSetting']['mailhost']; $mailuser=$setting['EwtSetting']['mailuser']; $mailpass=$setting['EwtSetting']['mailpass']; //$reportmail=$setting['EwtSetting']['reportmail']; $reportmail=$email; $bodymail=$this->EwtMailtemplate->read(null,$mailtemplate); //$header=$bodymail['EwtMailtemplate']['header']; //$footer=$bodymail['EwtMailtemplate']['footer']; //$title=$bodymail['EwtMailtemplate']['title']; $subject=“工作时间系统的新登录密码”; //$subject=$lastname.“.str_替换(“[date]”,$date,$title); //$header=str_replace(“[lastname]”,$lastname,$header); //$header=str_replace(“[date]”,$date,$header); //$footer=str_replace(“[lastname]”,$lastname,$footer); //$content=''.$header.'“$reportcontent.“$footer.”; $content='1 “.”“$reportcontent。”“; $this->Email->to=$reportmail; $this->Email->charset='UTF-8'; $this->Email->from=sprintf(“%s”,$fullname,$mailuser); $this->Email->replyto=sprintf(“%s”,$fullname,$mailuser); $this->Email->subject=$subject; $this->Email->sendAs='html'; $smtp=数组( “端口”=>25, “主机”=>$mailhost, “超时”=>99, “用户名”=>$mailuser, “密码”=>$mailpass ); $this->Email->smtpOptions=$smtp; $this->Email->delivery='smtp'; $bool=($this->Email->send($content))?true:false; $smtp_error=$this->Email->smtpError; 如果(strlen($smtp_错误)>0){ //$this->Session->setflash($smtp\u错误); $bool=false; } 如果(!$bool) { $this->redirect(数组('action'=>'userexists'); } 返回$bool; } },php,cakephp,cakephp-1.3,php-5.3,Php,Cakephp,Cakephp 1.3,Php 5.3,我使用该功能向用户提供的地址发送电子邮件。按下按钮后,将显示一个视图,我将此视图称为newpassword(使用相同的视图名称newpassword.ctp创建)。控制器功能如下所示: private function sendmail($userid, $reportcontent,$email){ //if($this->Session->read($this->_userName)) { $this->load

我使用该功能向用户提供的地址发送电子邮件。按下按钮后,将显示一个视图,我将此视图称为newpassword(使用相同的视图名称newpassword.ctp创建)。控制器功能如下所示:

private function sendmail($userid, $reportcontent,$email){
        //if($this->Session->read($this->_userName))
        {
            $this->loadModel('EwtMailtemplate');
            $this->loadModel('EwtUser');
            $this->loadModel('EwtSetting');
            $this->autoRender = false;

            $date = date("Y-m-d");
            $userinfo = $this->EwtUser->read(null, $userid);
            $fullname = $userinfo['EwtUser']['fullname'];
            $lastname = $userinfo['EwtUser']['lastname'];
            $mailtempl = $userinfo['EwtUser']['mailtempl'];
            if ($mailtempl == 0) {
                $mailtempl = 1;
            }

            $setting = $this->EwtSetting->find('first');
            $mailhost = $setting['EwtSetting']['mailhost'];
            $mailuser = $setting['EwtSetting']['mailuser'];
            $mailpass = $setting['EwtSetting']['mailpass'];
            //$reportmail = $setting['EwtSetting']['reportmail'];
            $reportmail=$email;
            $bodymail = $this->EwtMailtemplate->read(null, $mailtempl);
            //$header = $bodymail['EwtMailtemplate']['header'];
            //$footer = $bodymail['EwtMailtemplate']['footer'];
            //$title = $bodymail['EwtMailtemplate']['title'];
            $subject="New login password for working time system";
            //$subject = $lastname . " " . str_replace("[date]", $date, $title);
            //$header = str_replace("[lastname]", $lastname, $header);
            //$header = str_replace("[date]", $date, $header);
            //$footer = str_replace("[lastname]", $lastname, $footer);

            //$content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><html><head><meta http-equiv="Content-Type" content="text/html; charset =utf-8" /></head><body>'.$header ."<br />" . $reportcontent . "<br />" .  $footer . '</body></html>';

            $content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><html><head><meta http-equiv="Content-Type" content="text/html; charset =utf-8" /></head><body>'."<br />".$reportcontent."<br />".'</body></html>';

            $this->Email->to = $reportmail;
            $this->Email->charset = 'UTF-8';
            $this->Email->from = sprintf("%s <%s>", $fullname, $mailuser);
            $this->Email->replyto = sprintf("%s <%s>", $fullname, $mailuser);
            $this->Email->subject = $subject;
            $this->Email->sendAs ='html';
            $smtp = array(
                        'port'=>25,
                        'host'=>$mailhost,
                        'timeout'=>99,
                        'username'=>$mailuser,
                        'password'=>$mailpass
            );
            $this->Email->smtpOptions = $smtp;
            $this->Email->delivery = 'smtp';

            $bool=($this->Email->send($content))?true:false;

            $smtp_error = $this->Email->smtpError;
            if (strlen($smtp_error)>0){
                //$this->Session->setflash($smtp_errors);
                $bool=false;
            }
            if(!$bool)
            {
                $this->redirect(array('action'=>'userexists'));
            }
            return $bool;
        }
    }
    function newpassword()
        {
            $this->loadSkinForAction();
            $result=$this->EwtUser->get_user_from_email($_POST['email']);

            if(!empty($result))
            {
                $userid = $result[0]['ewt_users']['id'];
                $password=$this->EwtUser->get_and_change_user_password($_POST['email']);            
                $mail="Your new password is: ".$password."<br/>Please use it for next login.<br/>You are recommended to change this password again in your 'Personal Profile' section.";
                $bool = $this->sendmail($userid,$mail,$_POST['email']);

            }
            else
            {

                $this->redirect(array('action'=>'userexists'));
            }
        }
函数newpassword()
{
$this->loadSkinForAction();
$result=$this->EwtUser->get_user_from_email($_POST['email']);
如果(!空($result))
{
$userid=$result[0]['ewt_users']['id'];
$password=$this->EwtUser->获取并更改用户密码($\u POST['email']);
$mail=“您的新密码是:“..$password”。
请在下次登录时使用它。
建议您在“个人资料”部分再次更改此密码。“”; $bool=$this->sendmail($userid,$mail,$\u POST['email']); } 其他的 { $this->redirect(数组('action'=>'userexists'); } }
用于激发上述功能的表单如下所示:

private function sendmail($userid, $reportcontent,$email){
        //if($this->Session->read($this->_userName))
        {
            $this->loadModel('EwtMailtemplate');
            $this->loadModel('EwtUser');
            $this->loadModel('EwtSetting');
            $this->autoRender = false;

            $date = date("Y-m-d");
            $userinfo = $this->EwtUser->read(null, $userid);
            $fullname = $userinfo['EwtUser']['fullname'];
            $lastname = $userinfo['EwtUser']['lastname'];
            $mailtempl = $userinfo['EwtUser']['mailtempl'];
            if ($mailtempl == 0) {
                $mailtempl = 1;
            }

            $setting = $this->EwtSetting->find('first');
            $mailhost = $setting['EwtSetting']['mailhost'];
            $mailuser = $setting['EwtSetting']['mailuser'];
            $mailpass = $setting['EwtSetting']['mailpass'];
            //$reportmail = $setting['EwtSetting']['reportmail'];
            $reportmail=$email;
            $bodymail = $this->EwtMailtemplate->read(null, $mailtempl);
            //$header = $bodymail['EwtMailtemplate']['header'];
            //$footer = $bodymail['EwtMailtemplate']['footer'];
            //$title = $bodymail['EwtMailtemplate']['title'];
            $subject="New login password for working time system";
            //$subject = $lastname . " " . str_replace("[date]", $date, $title);
            //$header = str_replace("[lastname]", $lastname, $header);
            //$header = str_replace("[date]", $date, $header);
            //$footer = str_replace("[lastname]", $lastname, $footer);

            //$content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><html><head><meta http-equiv="Content-Type" content="text/html; charset =utf-8" /></head><body>'.$header ."<br />" . $reportcontent . "<br />" .  $footer . '</body></html>';

            $content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><html><head><meta http-equiv="Content-Type" content="text/html; charset =utf-8" /></head><body>'."<br />".$reportcontent."<br />".'</body></html>';

            $this->Email->to = $reportmail;
            $this->Email->charset = 'UTF-8';
            $this->Email->from = sprintf("%s <%s>", $fullname, $mailuser);
            $this->Email->replyto = sprintf("%s <%s>", $fullname, $mailuser);
            $this->Email->subject = $subject;
            $this->Email->sendAs ='html';
            $smtp = array(
                        'port'=>25,
                        'host'=>$mailhost,
                        'timeout'=>99,
                        'username'=>$mailuser,
                        'password'=>$mailpass
            );
            $this->Email->smtpOptions = $smtp;
            $this->Email->delivery = 'smtp';

            $bool=($this->Email->send($content))?true:false;

            $smtp_error = $this->Email->smtpError;
            if (strlen($smtp_error)>0){
                //$this->Session->setflash($smtp_errors);
                $bool=false;
            }
            if(!$bool)
            {
                $this->redirect(array('action'=>'userexists'));
            }
            return $bool;
        }
    }
    function newpassword()
        {
            $this->loadSkinForAction();
            $result=$this->EwtUser->get_user_from_email($_POST['email']);

            if(!empty($result))
            {
                $userid = $result[0]['ewt_users']['id'];
                $password=$this->EwtUser->get_and_change_user_password($_POST['email']);            
                $mail="Your new password is: ".$password."<br/>Please use it for next login.<br/>You are recommended to change this password again in your 'Personal Profile' section.";
                $bool = $this->sendmail($userid,$mail,$_POST['email']);

            }
            else
            {

                $this->redirect(array('action'=>'userexists'));
            }
        }

你的电子邮件地址

我现在遇到的问题是,第一个most函数的功能与我设想的一样,但在邮件发送后的最后一行,根本不显示视图(newpassword.ctp)。如果你们中有人能提供一些我犯过错误的地方,我真的很感激。非常感谢。

您正在将
$this->autoRender
设置为
false
。我认为这将为当前进程设置它,从而使调用函数(newpassword())autoRender也失效


我认为您的做法是错误的。

当您说视图根本不显示时,您的意思是输出是一个空白屏幕吗?我立即想到的是在
sendmail()
方法中重定向到
userexists
操作-尝试用调试语句替换它,看看它是否正在执行该行。我可能要补充一点,您在代码中违反了很多cakephp约定。我建议多花点时间读这本书。