4

当我尝试使用 Codeigniter 发送电子邮件时,电子邮件不会使用换行符发送。我尝试了一些编写 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']

请问有什么帮助吗?

4

2 回答 2

10

使用双引号"而不是单引号'。这样换行符\n就可以工作了。

于 2013-07-10T13:48:29.267 回答
3

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

于 2013-07-10T13:34:36.793 回答