4

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->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?

Oerd
  • 2,256
  • 1
  • 21
  • 35
Patrick
  • 1,265
  • 7
  • 21
  • 33

2 Answers2

17

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

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

John Flatness
  • 32,469
  • 5
  • 79
  • 81
-1

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