使用codeigniter发送html邮件

use*_*623 20 html email codeigniter

在codeigniter中使用SMTP的邮件内容出错实际上,我的邮件是带有HTML标签的,它显示的HTML标签不正确.

$config = Array(
'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'smtp_user' => 'user@gmail.com',
        'smtp_pass' => '',
        'mailtype'  => 'html', 
        'charset' => 'utf-8',
        'wordwrap' => TRUE

    );
    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");
    $email_body ="<div>hello world</div>";
    $this->email->from('user@gmail.com', 'ddd');

    $list = array('user@gmail.com');
    $this->email->to($list);
    $this->email->subject('Testing Email');
    $this->email->message($email_body);

    $this->email->send();
    echo $this->email->print_debugger();
Run Code Online (Sandbox Code Playgroud)

如果不使用SMTP发送邮件,它可以正常工作.我的错是什么?

Gab*_*iel 71

您可以尝试这行代码来设置邮件类型HTML:

 $this->email->set_mailtype("html");
Run Code Online (Sandbox Code Playgroud)


Mad*_*ota 22

作为笨3.X.添加了许多功能.此示例与早期版本几乎相同,但您可以执行更多操作.

请点击链接获取文档.

// load email library
$this->load->library('email');

// prepare email
$this->email
    ->from('info@example.com', 'Example Inc.')
    ->to('to@example.com')
    ->subject('Hello from Example Inc.')
    ->message('Hello, We are <strong>Example Inc.</strong>')
    ->set_mailtype('html');

// send email
$this->email->send();
Run Code Online (Sandbox Code Playgroud)

如果你有模板设计.你也可以在这样的message方法中包含模板......

->message($this->load->view('email_template', $data, true))
Run Code Online (Sandbox Code Playgroud)

在这里,第一个参数是email_template.php在你的意见目录,第二个参数将要发送的数据,以邮件模板,你可以将它设置''或者array()或者[]如果没有传递任何动态数据和最后一个参数true确定,你抢模板数据,而不是输出.

希望这是有帮助的.