【问题标题】:Form that sends html template to email将 html 模板发送到电子邮件的表单
【发布时间】:2016-10-21 13:34:36
【问题描述】:

表单内容已发送到我的电子邮件,但电子邮件中的 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>

【问题讨论】:

  • 电子邮件模板在哪里?
  • 什么是错误或输出??
  • 谢谢。 @xpuc7o 我已经更新并添加了我的模板,@ Abdulla 没有收到任何错误,只是出现纯文本,电子邮件上没有 css

标签: php html codeigniter


【解决方案1】:

我希望您没有将 Parser 库用于电子邮件模板,因此考虑到上述条件,下面是我的答案。

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

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

    很好,你成功了...

注意:不要使用 or etc 标签,也不要使用 &lt;table&gt; 而不是 &lt;div&gt;

【讨论】:

  • 尝试用内联css制作模板,所有代码都应该放在table标签内。
猜你喜欢
  • 1970-01-01
  • 2014-02-22
  • 2020-08-16
  • 1970-01-01
  • 1970-01-01
  • 2012-07-02
  • 2016-07-02
  • 2017-03-31
  • 2016-11-03
相关资源
最近更新 更多