Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is newline escape sequence not being converted into newline character?

I'm trying to send an email using codeigniter, and would like the message to span over several lines.

$address = $this->input->post('email');
$subject = 'Please complete your registration';
$message = 'Thanks for registering! \n To complete your registration, please click on (or copy and paste in your browser) the following link: ' . base_url(). "users/confirmRegistration/" . $confirmation_code; //note the '\n' after thanks for registering

$this->load->library('email');
    $this->email->from('[email protected]', 'myname');
    $this->email->to($address); 
    $this->email->subject($subject);
    $this->email->message($message);    
    $this->email->send();

I would expect the mail to arrive with a line break after "Thanks for registering", but instead i get

Thanks for registering! n To complete your registration (etc etc...)

I've tried with \r\n but the result is almost the same:

Thanks for registering! rn To complete (etc etc). It's like there were a stripslash function applied..

Any ideas?

like image 924
Patrick Avatar asked Dec 05 '22 02:12

Patrick


1 Answers

PHP doesn't parse escape sequences like \n inside single quotes.

You need to enclose your message string in double-quotes.

like image 181
John Flatness Avatar answered Jan 04 '23 22:01

John Flatness