首页 > 解决方案 > 如何在 view_login 中显示 set_flashdata?

问题描述

如何显示忘记密码的 set_flashdata 并在 codeigniter 中发送邮件?电子邮件控制器

    $dataemail = array(
            'subject'  =>$subjectupdate,
            'body'     =>$body, 
            'email'    =>$email,              
            'type'     =>'html'
        );

        sent_email($dataemail);
        $this->session->set_flashdata('message', 'chek email, klik button');
            redirect(site_url('v_login'));

view_login

    <div class="login_page_wrapper">
    <div class="md-card" id="login_card">
        <div class="md-card-content large-padding" id="login_form">
            <div class="login_heading">

                <div class="user_avatar1">
                    <?php if(isset($this->config->config['blogimgheader2']) AND $this->config->config['blogimgheader2']){ ?>
                     <img src="<?php echo $this->config->config['blogimgheader2'] ?>">
                    <?php }?>
                </div>
            </div>
            <form name="form_login" id="form-login" action="<?php echo site_url('login/validate_credentials'); ?>" method="post">
                <div class="uk-form-row">
                    <label for="login_username">username</label>
                    <input class="md-input" type="text" id="login_username" title="username" name="username" />
                </div>
                <div class="uk-form-row">
                    <label for="login_password">Password</label>
                    <input class="md-input" type="password" id="login_password" title="password" name="password" />
                </div>
                <div class="uk-margin-medium-top">
                    <button type="submit" class="md-btn md-btn-primary md-btn-block md-btn-lar-ge">Login</button>
                </div>
            </form>
        </div>

set_flashdata 没有出现

220 smtp.gmail.com ESMTP 14sm1123801pgp.37 - gsmtp 
hello: 250-smtp.gmail.com at your service, [103.79.90.13]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
from: 250 2.1.0 OK 14sm1123801pgp.37 - gsmtp
to: 250 2.1.5 OK 14sm1123801pgp.37 - gsmtp
to: 250 2.1.5 OK, duplicate recipients will be consolidated. 14sm1123801pgp.37 - gsmtp
data: 354  Go ahead 14sm1123801pgp.37 - gsmtp
250 2.0.0 OK 1560481437 14sm1123801pgp.37 - gsmtp 
quit: 221 2.0.0 closing connection 14sm1123801pgp.37 - gsmtp
Your message has been successfully sent using the following protocol: smtp

遇到 PHP 错误

严重性:警告

消息:无法修改标头信息 - 标头已发送(输出开始于 C:\xampp\htdocs\myweb\application\helpers\email_helper.php:26)

文件名:库/Session.php

行号:688

标签: codeigniter-3

解决方案


<?php 
    Class Myclass extends CI_Controller{

          public function __construct(){
             parent::__construct();
             //load session library
             $this->load->library('session');
          }

          public function register(){
              /*
              set email variables
             */
              if($this->email->send()) {
              //set flash data and redirect
                $this->session->set_flashdata('message', 'Please Check your email');
                redirect(site_url('v_login'));
              }  

           }
}
?>

现在在您的 view.php 中,编写下面的代码

<?php 
  if($this->session->flashdata('message') ? $this->session->flashdata('message') : '');
?>

推荐阅读