Pankaj Khurana
Pankaj Khurana

Reputation: 3271

Mail function issue

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

Upvotes: 0

Views: 49

Answers (3)

Felix Kling
Felix Kling

Reputation: 816262

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.

Upvotes: 3

prodigitalson
prodigitalson

Reputation: 60413

you need to use double quotes: "\n"

Upvotes: 1

arturh
arturh

Reputation: 6106

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

Upvotes: 1

Related Questions