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;
}
}
我使用该功能将电子邮件发送到用户提供的地址。按下按钮后,将显示一个视图,我将此视图称为newpassword(使用相同的视图名称newpassword.ctp创建)。控制器功能如下所示,
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'));
}
}
并且用于激发上述函数的表单编写如下,
<div id="form_pwd" style="display:none;">
<form method="POST" action="/working_time/ewt_users/newpassword" id="new_pwd">
<table>
<tr>
<td width="175px"><label for="email">Your email address</label></td>
<td><input type="text" name="email" id="email" size="35"/></td>
</tr>
<tr>
<td></td><td><input type="submit" value="Send" /></td>
</tr>
</table>
</form>
</div>
我现在面临的问题是,最重要的功能就像我想要做的那样,但是在邮件发送后的最后一行,视图(newpassword.ctp)根本没有显示。如果你们中的任何人能够提供一些关于我所犯错误的地方,我真的很感激。非常感谢你。
答案 0 :(得分:0)
您将$this->autoRender
设为false
。我认为这将为当前进程设置它,从而使调用函数(newpassword())autoRender也无效。
我认为你正在以错误的方式接近这个恕我直言。