电子邮件的Codeigniter换行符不起作用?

时间:2013-07-10 13:31:41

标签: php codeigniter email newline

当我尝试使用Codeigniter发送电子邮件时,不会使用换行符发送电子邮件。我尝试了一些tecniques写的stackoverflow但没有工作。

这是我的代码:

 $message = 'Hi everyone\r\n';
 $message .= 'Today you can look at these sites\r\n';
 $message .= 'Have a good days';

 $config['charset'] = 'utf-8';
 $config['mailtype'] = 'text';
 $config['newline'] = '\r\n';

 $this->load->library('email');
 $this->email->initialize($config);
 $this->email->from('xxxxx@xxx.com');
 $this->email->to('aaaa@aaaaaa.com');

 $this->email->subject('Today New Sites');
 $this->email->message($message);
 $this->email->send();

我也试过了:

1.instead of putting \r\n, I put only \n and changed $config['newline'] = '\n'
2.I tried $this->email->message(nl2br($message));
3.I tried : str_replace('\r\n','"\r\n",$message);
4.I get rid of $config['mailtype']

请帮忙吗?

2 个答案:

答案 0 :(得分:9)

使用双引号"代替单引号'。这样换行\n就可以了。

答案 1 :(得分:2)

更改$config['mailtype'] = 'html';并使用<br/>