为什么newline转义序列没有转换为换行符?

Pat*_*ick 4 php email codeigniter escaping

我正在尝试使用codeigniter发送电子邮件,并希望该消息跨越多行.

$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();
Run Code Online (Sandbox Code Playgroud)

我希望邮件在"感谢注册"之后以换行符到达,但我得到了

感谢您的注册!ñ完成注册(等等......)

我试过\ r \n但结果几乎相同:

感谢您的注册!要完成(等等).这就像应用了striplash功能..

有任何想法吗?

Joh*_*ess 17

PHP不像\n单引号那样解析转义序列.

您需要将消息字符串括在双引号中.