开发者

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

开发者 https://www.devze.com 2022-12-29 04:55 出处:网络
I\'m trying to send an email using codeigniter, and would like the message to span over several lines.

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('me@mysite.com', 'myname');
    $this->email->to($address); 
    $this->email->subject($subject);
    $this->email->message($message);    
    $this->email-&g开发者_运维知识库t;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?


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

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


You need to type body in this format. It works fine. Rahul

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

' . 'Your account with us has been temporarily disabled.' . '

' . 'Our facilitator relationship team shall contact you soon.' . '

' . 'You can also get in touch with us on info@ggg.com' . '

' . 'Warm Regards, ' . '

' . ' The Team';

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号