Codeigniter Html电子邮件显示Html源代码


Codeigniter Html Email Display HTML Source Code

尝试发送电子邮件,但它的邮件格式是HTML源代码。这是mY控制器-

$config = Array(        
        'protocol' => 'SMTP',
        'smtp_host' => 'hostname',
        'smtp_port' => 'portname',
        'smtp_user' => 'abn@gmail.com',
        'smtp_pass' => '***',
        'smtp_timeout' => '4',
        'mailtype'  => 'html',
        'charset'   => 'utf-8'
    );
    $this->load->library('email', $config);
    $this->email->set_newline("'r'n");
    $this->email->from('devendra@gmail.com', 'ABC');
    $data = array(
         'userName'=> $this->input->post('email'),
         'password'=> $this->input->post('password'),
         'EmpName'=> $this->input->post('name'),
         'Number'=> $this->input->post('number'),
         'City'=> $this->input->post('city'),
         'State'=> $this->input->post('email'),
         'Address'=> $this->input->post('address')
             );
    $this->email->to($this->input->post('email')); 
    $Subject = 'User Login Details';
    $this->email->subject($Subject); 
    $body = $this->load->view('mailFormat.php',$data,TRUE);
    $this->email->message($body);   
    $this->email->send();

和电子邮件格式页面mailFormat.php

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Employee Registration</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<div>
 <div style="font-size: 26px;font-weight: 700;letter-spacing: -0.02em;line-height: 32px;color: #41637e;font-family: sans-serif;text-align: center" align="center" id="emb-email-header"><img style="border: 0;-ms-interpolation-mode: bicubic;display: block;Margin-left: auto;Margin-right: auto;max-width: 152px" src="<?php echo base_url(); ?>/images/logo.png" alt="WFT" width="152" height="108"></div>
 <p style="Margin-top: 0;color: #565656;font-family: Georgia,serif;font-size: 16px;line-height: 25px;Margin-bottom: 25px">Hey  <?php echo $EmpName;?>,</p> 
<p>Email Id - <?php echo $userName; ?> </p>
<p>Password - <?php echo $password; ?> </p>
<p>Contact Number - <?php echo $Number; ?> </p>
<p>City - <?php echo $City; ?> </p>
<p>State - <?php echo $State; ?> </p>
<p>Address - <?php echo $Address; ?> </p>
</div>
</body>
</html>

已发送电子邮件。但显示HTML源代码的电子邮件格式。如何将其更改为HTML格式的电子邮件。

如前所述,您可以使用mailtype配置,但这里有更多详细信息以及如何正确执行。

设置电子邮件首选项

有21种不同的偏好可用于定制您的电子邮件发送消息。您可以按照此处所述手动设置它们,或通过存储在配置文件中的首选项自动执行,如所述下图:

通过向电子邮件初始化方法。以下是如何设置首选项:

$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';         // use this setting
$this->email->initialize($config);

电子邮件类

$this->email->mailtype('html'); // This was incorrect, check below for what I used

Codeigniter电子邮件类

这是我以前用过的一种方法,希望它能帮助

    //Setting up the email
    $config = array(
    'protocol' => 'smtp',
    'smtp_host' => 'smtp.host.com',
    'smtp_port' => 587,
    'smtp_user' => '******',
    'smtp_pass' => '******',
    'mailtype'  => 'html',
    'charset'   => 'iso-8859-1'
);
    $this->load->library('email', $config);
    $this->email->set_newline("'r'n");
    $data = array(
    'email'    => $user->user_email,
    'username' => $user->user_first_name,
    'token'    => $token,
);
    $this->email->from('*******', 'Title');
    $this->email->to($user->user_email);
    $this->email->subject('***** - Password Reset Request');
    $html = $this->load->view('help/email/forgot_password', $data, true);
    $this->email->message($html);
    $this->email->send();

因此,我认为首先将其设置为变量是我修复它的方法。