2012-03-03 2 views
1

Я также не уверен, почему у меня возникают следующие ошибки при попытке передать данные в мой шаблон электронной почты html -> Ошибки PHP поступают из представления.Codeigniter -> Undefined Variable

Undefined variable: companyName -> line 9 

Undefined variable: firstName -> line 12 

Контроллер:

function _userRegEmail($activateCode,$email,$firstname,$lastname){ 
     $data['companyName'] = $this->core_model->companyDetails()->coreCompanyName; 
     $data['companyEmail'] = $this->core_model->companyDetails()->coreContactEmail; 
     $data['companyContact'] = $this->core_model->companyDetails()->coreContactName; 
     $data['firstName'] = $firstname; 
     $data['lastName'] = $lastname; 
     $data['email'] = $email; 
     $data['activateCode'] = $activateCode; 

     $this->email->from($this->core_model->companyDetails()->coreContactEmail, $this->core_model->companyDetails()->coreCompanyName); 
     $this->email->to($email); 
     $this->email->subject($this->core_model->companyDetails()->coreCompanyName 'User Registration Confirmation'); 

     $messageContent= $this->load->view('email_templates/userReg','', TRUE); 

     $this->email->message($messageContent); 

     $this->email->send(); 

     echo $this->email->print_debugger(); 
    } 

Вид:

<html> 
    <head> 
    <meta http-equiv="Content-type" content="text/html; charset=utf-8"/> 
    <title/> 
    </head> 
    <body> 
    <div class="container" style="width: 600px;height: 100%;margin: 0 auto;font-family: Arial, &quot;MS Trebuchet&quot;, sans-serif"> 
     <div class="header" style="width: 100%"> 
      <h1 style="text-align: center;color: #00afd8"><?php echo $companyName; ?></h1> 
      </div> 
       <div class="content"> 
        <h2 style="font-size: 15px">Hello <?php echo $firstName; ?></h2> 
       <p style="margin-left: 15px">Thank you for signing up to Farm Ads.</p> 
       <p style="margin-left: 15px">Could you please click <a href="<?php base_url(); ?>users/confirm/"<?php $activateCode; ?>>here</a> to activate your account.</p> 

       <div class="from"> 
        <p class="bold" style="margin-left: 15px;font-weight: bold;font-size: 12px">Regards,</p> 
        <p style="margin-left: 15px;font-weight: bold;font-size: 12px"><?php $companyContact; ?></p> 
        </div> 
      </div> 
     </div> 

</body> 
</html> 

ответ

1

Если вы хотите использовать переменные, которые вы установили в $ данных с точки зрения вы не должны делать :

$messageContent= $this->load->view('email_templates/userReg','', TRUE); 

Но:

$messageContent= $this->load->view('email_templates/userReg', $data, TRUE); 

Это делает, что вы посылаете переменные в представлении, так что они могут быть использованы там, как вы пытаетесь уже.