Why can't a newline escape sequence be converted to a newline?

I am trying to send an email using codeigniter and would like the message to span multiple 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(' me@mysite.com ', 'myname'); $this->email->to($address); $this->email->subject($subject); $this->email->message($message); $this->email->send(); 

I expect mail to arrive with a line break after β€œThanks for signing up,” but instead I get

Thank you for registering! n To complete the registration (etc.) ...

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

Thank you for registering! rn Finish (etc.). As if stripslash function was applied.

Any ideas?

+4
source share
2 answers

PHP does not parse escape sequences such as \n inside single quotes.

You need to enclose the message string in double quotation marks.

+17
source

You need to dial the body in this format. It is working fine. Rahul

$ body = 'Dear'. $ row-> fname. ''. $ row-> lname. ','.

'. "Your account with us is temporarily disabled.",

. "Our coordinating team will contact you shortly.",

. "You can also contact us at info@ggg.com ."

. 'Best wishes, '.

. "Command";

-1
source

Source: https://habr.com/ru/post/1308697/


All Articles