tags:

views:

15

answers:

3

Hi,

I am using mail function as i want to send message in a format for that i have used '\n' but it is showing as \n , the text does not comes in the second line.

My code is :

$to  = '[email protected]'; 
$from='[email protected]';
$sendername='user';
$replyto='[email protected]';
$subject='Enrollment in Course';
$message='Please enroll '.$enrolmentdetails[0][email].' in Coursefor '.$enrolmentdetails[0][productname].'.';
$message.='\nOther Details are:\nFirstname : '.$enrolmentdetails[0][cf_549].'\nLastname : '.$enrolmentdetails[0][lastname].'\nMobile No : '.$enrolmentdetails[0][cf_591];
if(sendEMail($to, $from, $sendername, $replyto, $subject, $message))
showMessage('Email with student details sent successfully.', 'main-content', 'divMsg', APP_URL."views/completeenrollments.php", 3000, 'success');
else
showMessage('There was some problem sending student details. Please try again later', 'main-content', 'divMsg', APP_URL."views/completeenrollments.php", 3000, 'error');

Right now i am getting this :

Please enroll [email protected] in Course for FP - LVC Plus.\nOther Details are:\nFirstname : new \nLastname : user\nMobile No : 121213313

Please help me on this

Thanks

+3  A: 

If you want to use the newline character (or any special character), you have to enclose the string into double-quotes ".
E.g.

$message.="\nOther Details are:\nFirstname : ".$enrolmentdetails[0][cf_549]."\nLastname : ".$enrolmentdetails[0][lastname]."\nMobile No : ".$enrolmentdetails[0][cf_591];

Read about single quoted and double quoted strings in PHP.

From the documentation about single quoted strings:

Note: Unlike the three other syntaxes, variables and escape sequences for special characters will not be expanded when they occur in single quoted strings.

Felix Kling
thanks felix changing single quote to double quote resolved the issue.
Pankaj Khurana
+1  A: 

That is because when using ' there is no interpretation of special characters like \n. Use " instead.

arturh
+1  A: 

you need to use double quotes: "\n"

prodigitalson