【问题标题】:able to send simple mail but unable to send my html view file in sending mail code igniter能够发送简单邮件但无法在发送邮件代码点火器中发送我的 html 视图文件
【发布时间】:2020-07-25 08:51:13
【问题描述】:

我可以发送邮件,但现在我正在尝试以正确的方式发送邮件,这样看起来很适合recwiver,所以我想附加一个 html 视图文件,因为它看起来也发送了 html 文件,但我不能在其中发送适当的数据,因为它不会动态更改其显示的统计值。

这是我的控制器代码.....

  public function forgetuser()
    {
        $Uid = $this->input->post('uid');
      

        
        $otp = rand(10,1000000);

        $mail =  $dat = $this->Lib_model->Select('ur_super_users', '*', array('isActive'=> 1,'id' => $Uid));

$receiverMail = $mail[0]->emailId;
       $count = 0 ;



       if ($count == 0) {
           
           $f = array(
               'otp' => $otp,
               
               

           );

           $this->Lib_model->Update('ur_super_users', $f, array('id' => $Uid));
           //$this->Lib_model->Insert('ur_super_users', $f);
           
//mailer request
$data = Forget_Mail ($receiverMail, $Uid,$otp,$dat);
          

 if (!empty($insert_users)) {
            $Msg = array('Msg' => 'Assigned Successfully', 'Type' => 'success');
            $this->session->set_flashdata($Msg);
            redirect(base_url('/frontend/homepage/forget'));
        }

我的邮件助手功能----

if (!function_exists('Forget_Mail')) {

    function Forget_Mail($email, $Uid, $otp,$dat)
    {
        $otp = $otp;
        $Uid = $Uid ;
        $to_email = $email;


        $link = 'http://www.abcd.com/frontend/homepage/forgetpwd/'.$Uid.'/'.$otp.'';

        $BaseUrl = '"<?php echo base_url() ?>"'; 

        $from_email = 'info@abcd.com';

        
        $user = array('Uid' =>  $Uid , 'otp' => $otp);
        //$from_name = 'abcd';
        $from_name = 'abcd';

        $config = array(

            'protocol' => 'smtp',
            'smtp_host' => 'ssl://smtp.googlemail.com',
            'smtp_port' => 465,
            'smtp_user' => 'xyz@gmail.com',
            'smtp_pass' => 'xyz@1236',
            'mailtype'  => 'html',
            'charset'   => 'iso-8859-1'
        );
        $CI = &get_instance();
        $CI->load->library('email', $config);
        $CI->email->set_newline("\r\n");
        $CI->email->from($from_email, $from_name);
        $CI->email->to($to_email);  // replace it with receiver mail id
        $CI->email->subject('Forget Password Link |'  . $from_name); // replace it with relevant subject

//request for html view page to in mail it is loading but not sending varible array value

        $body = $CI->load->view('email_templates/forget', $user, TRUE);
       
       
       
         $CI->email->message($body);
        //Send mail 
        if ($CI->email->send()){
            //prx($link);
            
        redirect(base_url('/frontend/homepage/forget'));
        
       // return true;
         } else{return true;
          // return false;}
         }
    }
}

我的视图html文件forget.php

 <br>
    Click here to Reset Your Password : <b><a href="http://abcd.com/frontend/homepage/forgetpwd/'.$Uid.'/'.$otp.' ">

//this is coming same in received mail not changing with each user 
         
         Reset Password</a></b>

    <br>

【问题讨论】:

    标签: php codeigniter phpmailer codeigniter-3


    【解决方案1】:

    我认为问题在于您没有将变量打印/回显到 html 代码。 (假设提供了一部分forget.php 代码)。您可以尝试以下任一方法:

    • 将视图更改为
    <br>
        Click here to Reset Your Password : <b><a href="http://abcd.com/frontend/homepage/forgetpwd/<?= $Uid; ?>/<?= $otp; ?>">
         
       Reset Password</a></b>
    
    <br>
    

    $CI->load->library('parser');
    $user = array(
            'Uid' => $Uid , 
            'otp' => $otp
    );
    
    $body = $CI->parser->parse('email_templates/forget', $user, TRUE);
    
    **
    
    $CI->email->message($body);
    
    **
    

    并将你的 forget.php 更改为

    <br>
        Click here to Reset Your Password : <b><a href="http://abcd.com/frontend/homepage/forgetpwd/{Uid}/{otp}">
    
    //this is coming same in received mail not changing with each user 
             
       Reset Password</a></b>
    
    <br>
    

    【讨论】:

    • @animeshsoni 欢迎来到 SO。请阅读此here
    • 实际上我现在不能投票,因为我没有特权
    • 但我再次感谢你的回答 thnx
    【解决方案2】:

    Use the Template Parser Class in Codeigniter. https://codeigniter.com/userguide3/libraries/parser.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-06
      • 2012-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多