Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter newline for email does not work?

When I try to send email with Codeigniter email is not send with newlines. I tried some of tecniques written stackoverflow but not worked.

Here is my codes :

 $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('[email protected]');
 $this->email->to('[email protected]');

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

I tried those also :

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']

Any help please?

like image 495
kalaba2003 Avatar asked Dec 11 '22 13:12

kalaba2003


2 Answers

Use double-quotes " instead of single-quotes '. This way the newline \n will work.

like image 90
Fracsi Avatar answered Dec 28 '22 19:12

Fracsi


Change $config['mailtype'] = 'html'; and use <br/>.

like image 33
Nil'z Avatar answered Dec 28 '22 20:12

Nil'z