2012-03-09 18 views
0
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

ビューが表示されないと言うと、出力が空白の画面であることを意味しますか?すぐに私に飛びつくのは、 'sendmail()'メソッドの 'userexists'アクションへのリダイレクトです。これをdebugステートメントに置き換えて、その行を実行しているかどうかを確認してください。 –

答えて

0

$this->autoRenderからfalseに設定しています。私はこれが現在のプロセスのためにそれを設定し、呼び出し関数(newpassword())autoRenderも無効にすると思います。

私は間違った方向IMHOに近づいていると思います。

+0

あなたのコードでかなりのcakephpの規則を無視しています。私は本を​​読んでもう少し時間を費やすことを提案するでしょう。 –

関連する問題