将html模板发送到电子邮件的表单

时间:2016-10-21 13:34:37

标签: php html5 codeigniter

表单内容将发送到我的电子邮件,但电子邮件中无法识别HTML和CSS代码。只输出纯文本。

以下是我的控制器

public function registration() {

    $email = $this->input->post('email');
    $domain = $this->input->post('domain_name');
    $passw = $this->input->post('passw');
    $name = $this->input->post('name');
    $skype = $this->input->post('skype');
    //  $package = $this->input->post('package');

    $config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'xxxx.com',
        'smtp_port' => 25,
        'smtp_user' => 'xxx@xxxxxx.com',
        'smtp_pass' => 'xxxxx',
        'mailtype' => 'html',
        'charset' => 'iso-8859-1'
    );

    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");
    $this->email->from('xxx@xxxxxx.com', 'welcome');
    $this->email->to('xxxxx@xxxxxxxx.com');

    $this->email->subject('registration');

    $body = $this->load->view('dns/template', TRUE);


    $this->email->message($body, TRUE);

    $this->email->send();

    $data['message'] = 'Submitted Sucessfullly';
    $data['emails'] = $this->Dns_model->emails($domain);

    $this->load->view('dns/sucessful', $data);
}

以下是我保存为template.php的视图

我的观点(模板)

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<html> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Registration</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="<?php echo base_url()?>/assets/bootstrap/css/bootstrap.min.css">
  <link rel="stylesheet" href="<?php echo base_url()?>/assets/css/bootstrap.css">
  <link rel="stylesheet" href="<?php echo base_url()?>/assets/css/bootstrap-responsive.min.css">
   <link rel="stylesheet" href="<?php echo base_url()?>/assets/css/font-awesome.min.css">
    <link rel="stylesheet" href="<?php echo base_url()?>/assets/css/main.css">
    <link rel="stylesheet" href="<?php echo base_url()?>/assets/css/style.css">
    <link rel="stylesheet" href="<?php echo base_url()?>/assets/css/AdminLTE.css">
    <link rel="stylesheet" href="<?php echo base_url()?>/assets/css/sl-slide.css">

    <script src="<?php echo base_url()?>/assets/js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
    <script src='https://www.google.com/recaptcha/api.js'></script>

    <!-- Le fav and touch icons -->
    <link rel="shortcut icon" href="<?php echo base_url()?>/images/ico/favicon.ico">
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="<?php echo base_url()?>/images/ico/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="<?php echo base_url()?>/images/ico/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="i<?php echo base_url()?>/mages/ico/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="<?php echo base_url()?>/images/ico/apple-touch-icon-57-precomposed.png">

 </head>

<body id="con"  onLoad="generate();">
<div id="fb-root"></div>
<div class="container">
<section class="main-info">
<br>
<section id="recent-works3">

<section id="pricing-table">


    <div class="row-fluid center clearfix">



        <div class="span3">

        </div>



        <div class="span6">
 <ul class="plan plan3">
                    <li class="plan-name">             
                        <span class="lead3">Emails to be setup</span>
                    </li>
  </ul>
  <table class="table">
    <thead>
    <tr>
     <th>Email</th>
     <th>Password</th>
     </tr>
    </thead>
    <tbody>
     <tr class="info">
     <td>info@test.com</td>
     <td>terfwws6w</td>
      </tr>
    </tbody>
    </table>
    <ul class="plan plan3">
      <li class="plan-action">
       <a href="http://www.xxxxxx.com" class="btn btn-transparent">Registration website</a>
         </li>
            </ul>
        </div>

        <div class="span3">


        </div>
    </div>
</section>
</section>
</section>
</div>
</div>                       
 <script src="<?php echo base_url()?>/assets/js/vendor/jquery-1.9.1.min.js">     </script>
 <script src="<?php echo base_url()?>/assets/js/vendor/bootstrap.min.js"></script>
 <script src="<?php echo base_url()?>/assets/js/main.js"></script>
<script src="<?php echo base_url()?>/assets/js/jquery.ba-cond.min.js"></script>
   </body>
   </html>

1 个答案:

答案 0 :(得分:0)

我希望您没有将Parser库用于电子邮件模板,所以请考虑以上条件,以下是我的答案。

  1. 你的模板有问题,意味着你在那里写的Html代码,它们有不匹配的标签或在错误的地方使用的某些标签。所以你必须先检查一下。

  2. 如果您仍然无法找到问题,那么您只需使用下面的代码创建一个模板,您将看到邮件不再是普通文本..

    很好,你钉了它......
  3.   

    注意:请勿使用或等标记,并使用<table>代替<div>