开发者

Mail function issue

开发者 https://www.devze.com 2023-01-01 11:29 出处:网络
I am using mail function a开发者_如何学Pythons 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.

I am using mail function a开发者_如何学Pythons 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  = 'user@mydomain.in'; 
$from='admin@mydomain.in';
$sendername='user';
$replyto='admin@mydomain.in';
$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 newuser@gmail.com in Course for FP - LVC Plus.\nOther Details are:\nFirstname : new \nLastname : user\nMobile No : 121213313

Please help me on this

Thanks


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.


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


you need to use double quotes: "\n"

0

精彩评论

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

关注公众号