邮件功能不以HTML格式发送

时间:2013-08-13 17:10:06

标签: codeigniter php

巨大的编辑!!!!!!!!! 好吧,所以它不是HTML或其他什么。当我在PHP消息变量中粘贴它时,它发送完全格式化。这是textarea盒子粘贴部分...这使它无法正常工作。这是换行吗?......嗯。

好的,这对我来说是令人沮丧的一天。我正在尝试发送HTML电子邮件,我可以将其粘贴到textarea的邮件中。好吧,我把它剥离到准系统,它不会让身体上方和身体被放入HTML之后的任何东西。

打印出来:

<html> <head> <title>HalfOffDeals - Thank you!</title> </head> <body>

然后它吐出身体......虽然没有格式化,但没有格式化。

然后这个:

</body> </html>

我尝试使用样式标记来设置内联CSS,它完全省略了它。我正在使用CodeIgniter,我不知道它是否自动剥离它不应该...我有一个表单(TO,SUBJECT和MESSAGE)。在邮件部分中,您粘贴HTML电子邮件模板,并假设要发送到电子邮件。

我的另一个问题是如何在标题中添加'':

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";

我只是为什么我的电子邮件不接受HTML而感到困惑。这就是我设置它的方式:

public function send_email() {
    $to = $this->input->post('to');
    $subject = $this->input->post('subject');
    $message .= $this->input->post('message');

    // To send HTML mail, the Content-type header must be set
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";

    // Additional headers
    $headers .= 'To: Customer <'.$to . "\r\n";
    $headers .= 'From: noreply@intellectproductions.com <noreply@intellectproductions.com>' . "\r\n";

    // Mail it
    mail($to, $subject, $message, $headers);
}

有什么想法吗?

这是电子邮件模板:http://pastebin.com/D04cLXe4

4 个答案:

答案 0 :(得分:4)

 $headers .= 'To: Customer <'.$to . "\r\n";

更改为

 $headers .= 'To: Customer <'. $to .'>'."\r\n";

并尝试:

$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";

change to 

$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";

你的服务器是linux,如果windows“\ r \ n”

,换行符是“\ n”

答案 1 :(得分:1)

我发现你确实在使用CodeIgniter - 所以,我建议使用CodeIgniter's Email class

尝试将您的功能更改为:

public function send_email() {
    $to = $this->input->post('to');
    $subject = $this->input->post('subject');
    $message .= $this->input->post('message');

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

    // To send HTML mail, set the appropriate mailtype
    $this->email->set_mailtype('html');

    // setup the message
    $this->email->to($to);
    $this->email->from('noreply@intellectproductions.com');
    $this->email->subject('Put the subject here');
    $this->email->message($message);

    // Mail it
    $this->email->send();
}

即使他们有附件,这也可以处理HTML电子邮件。 将代码保存到重要的位置,不要need to do all this work。 ;)

答案 2 :(得分:0)

要在电子邮件中发送html,您可以使用默认CI电子邮件设置;

    $this->load->library('email');
    $config = array(
        'mailtype' => 'html',
        'newline' => '\r\n',
        'charset' => 'utf-8' //default charset
    );
    $this->email->initialize($config);
    $this->email->from($sender);
    $this->email->to($receiver);
    $this->email->subject($subject);
    $this->email->message($message);
    $this->email->send();

有关详细信息,请参阅CI email class。 另请尝试使用$this->email->print_debugger()查看电子邮件错误/

答案 3 :(得分:0)

当我使用PHP邮件功能时,我也遇到了一些问题。然后我遇到了类phpmailer ,我的问题就结束了。好好看看它。这是值得的。