【问题标题】:Sending html email displays as code in codeigniter发送 html 电子邮件在 codeigniter 中显示为代码
【发布时间】:2015-05-28 07:30:33
【问题描述】:

我在发送 html 电子邮件 codeigniter 时遇到问题。对于文本来说还可以,但在使用 html 进行样式设置时,它总是显示代码。搜索了很多并将该电子邮件配置数组项更改为许多。但结果是相同的 html 代码。请帮帮我..

这是我的控制器功能

public function contact_process()
{
    $name=$this->input->post('txt_name');
    $phone=$this->input->post('txt_phone');
    $from_email=$this->input->post('txt_email');
    $message=$this->input->post('txt_message');
    $config = Array(
        'protocol' => 'sendmail',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'smtp_user' => 'my_email_id@gmail.com',
        'smtp_pass' => 'my_password',
        'mailtype'  => 'html', 
        'charset' => 'utf-8',
        'priority' => '1',
        'wordwrap'  => 'true'
    );
    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");
    $to_email = 'to_email_id@gmail.com';
    $subject = "Product Request Mail";
    $body = "<html>
            <head><title>Best Price</title></head>
            <body>
            <div style='max-width: 800px; margin: 0; padding: 30px 0;'>
            <table width='80%' border='1' cellpadding='0' cellspacing='0'>
            <tr>
            <td width='5%'></td>
            <td align='left' width='95%' style='font: 13px/18px Arial, Helvetica, sans-serif;'>
            <h2 style='font: normal 20px/23px Arial, Helvetica, sans-serif; margin: 0; padding: 0 0 18px; color: black;'>Contact Mail</h2>
            <br />
            <big style='font: 16px/18px Arial, Helvetica, sans-serif;'> Name : '.$name.'</big><br />
            <big style='font: 16px/18px Arial, Helvetica, sans-serif;'> Phone : '.$phone.'</big><br />
            <big style='font: 16px/18px Arial, Helvetica, sans-serif;'> Email : '.$from_email.'</big><br />
            <big style='font: 16px/18px Arial, Helvetica, sans-serif;'> Message : '.$message.'</big><br />
            </td>
            </tr>
            </table>
            </div>
            </body>
            </html>";
    //send mail
    $this->email->from($from_email, $name);
    $this->email->to($to_email);
    $this->email->subject($subject);
    $this->email->message($body);
    //echo $this->email->send();
    //echo $this->email->print_debugger();
    if ($this->email->send())
    {
        redirect('user/bestprice/contact/', 'refresh');
    }
    else
    {
        redirect('user/bestprice/contact/', 'refresh');
    }                
}

【问题讨论】:

    标签: html codeigniter email


    【解决方案1】:

    你没有提到邮件包含 HTML。

    使用这个

    $this-&gt;email-&gt;set_mailtype("html");

    【讨论】:

    • 我认为配置数组中的 'mailtype' => 'html' 就足够了。谢谢@Abdulla
    猜你喜欢
    • 2011-09-10
    • 2017-01-22
    • 2018-12-29
    • 2012-01-06
    • 2012-12-29
    • 2022-11-18
    • 2016-11-23
    • 2016-07-28
    • 1970-01-01
    相关资源
    最近更新 更多