尝试发送电子邮件但它邮寄的格式是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格式的电子邮件。
答案 0 :(得分:0)
$this->email->mailtype('html'); // This was incorrect, check below for what I used
这是我用了一段时间的方法,希望有所帮助
//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();
所以我认为首先将它设置为变量就是我要做的事情。
答案 1 :(得分:0)
您可以使用已经说过的 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);