CodeIgniter:HTML电子邮件到达空白

时间:2012-03-04 01:46:03

标签: php email codeigniter

我正在尝试使用 Thunderbird 接收以下电子邮件,但它已空白。 from和subject *完好无损,但消息为空白,print_debugger();显示所有内容**等

*主题显示公司名称,但不显示“用户注册确认”文本

**我在print_debugger();页面上也遇到以下错误,但我认为这是由print_debugger();

引起的

Message: Cannot modify header information - headers already sent by line 72 -> echo $this->email->print_debugger(); for both the session and url_helper

配置:

$config['protocol'] = 'mail';
$config['wordwrap'] = FALSE;
$config['send_multipart'] = FALSE ;
$config['mailtype'] = 'html';

控制器:

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',$data, 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 个答案:

答案 0 :(得分:2)

您没有将$data传递给视图。而不是:

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

试试这个:

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

在电子邮件主题行的代码中,您忘记了.来连接两个字符串:

$this->email->subject($this->core_model->companyDetails()->coreCompanyName.' User Registration Confirmation');

您的观点中也存在错误。 $activateCode应该在<a href="">的引号内,而不在外面。你在视图中的几个地方忘记了echo

<a href="<?php echo base_url(); ?>users/confirm/<?php echo $activateCode; ?>">here</a>