MyBB Community Forums

Full Version: Send Private Message With Multi Lines?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
i am developing a plugin which sends a private message when i try to make it have multiple lines by putting
$message = "Well heres my messages first line
and here is the second line
";

When the user receives the message it says this
Well heres my messages first line\nand here is the second line
Enable HTML in Private Message ?

ACP > Configurations > Private Messaging > and select Yes in "Allow HTML".

But allowing HTML is a risk.
(2011-01-14, 05:17 AM)Yaldaram Wrote: [ -> ]Enable HTML in Private Message ?

ACP > Configurations > Private Messaging > and select Yes in "Allow HTML".

But allowing HTML is a risk.

So why would i want to do that? :|
I said that because \n is an HTML tag, which can only parsed if you've HTML enabled in PM-s
(2011-01-14, 10:38 AM)Yaldaram Wrote: [ -> ]I said that because \n is an HTML tag, which can only parsed if you've HTML enabled in PM-s

But what my original message was.
Is in the PHP code i am adding several lines like this:
$message = "Line one
Line two
Line three
";
But when the user recives it, it displays like this.
Line one\nLine two\nLine three
Enabling HTML won't work simply because it's not HTML. If you try putting \n in a PM, enable HTML in PMs, and it won't turn it into a new line.

@K1LL3RCL0WN what code are you using to insert the PM?? In MySupport I have a function to send a PM, the language string has multiple lines in that, and it doesn't show \n anywhere.
Also, are you escaping the $message variable in any way before sending to the PM handler? If you are then don't because then the message will end up getting escaped twice.

If the above does not apply to you then what editor are you using to edit your php files? I always prefer to use Notepad++ and setting the EOL to Unix format to avoid any problems (Edit > EOL). You might want to try doing that.
This is what i am using.
Any strings that aren't there are set at the top of the page with just simple things like $example = "1"; $example2 = "Hello the message that tried to have multi lines
and here is the messages second line";
        $pmhandler = new PMDataHandler();

        	$pm = array(
            		"subject" => $db->escape_string($subject),
            		"message" => $db->escape_string($message),
                           "icon" => '0',
            		"fromid" => $fromID,
            		"do" => '',
            		"pmid" => ''
       		);
		$pmadmin = get_user($user['uid']);

		$pm['to'] = explode(",",$pmadmin['username']); //{$mybb->user['uid']
		$pm['to'] = array_map("trim", $pm['to']);

        	$pm['options'] = array(
	    		"savecopy" => "no",
            		"saveasdraft" => 0,
            		"signature" => $IncSig,
            		"disablesmilies" => $SmiliesStatus,
        	);

    		$pmhandler->admin_override = 1;
    		$pmhandler->set_data($pm);
     if ($iStatus == "on"){
    		if(!$pmhandler->validate_pm())
    		{
        		$pm_errors = $pmhandler->get_friendly_errors();
				$send_errors = inline_error($pm_errors);
    		}
    		else
    		{
        		$pminfo = $pmhandler->insert_pm();
			}
                         }

Hope i've included all details :\
(2011-01-14, 11:03 AM)- G33K - Wrote: [ -> ]Also, are you escaping the $message variable in any way before sending to the PM handler? If you are then don't because then the message will end up getting escaped twice.

If the above does not apply to you then what editor are you using to edit your php files? I always prefer to use Notepad++ and setting the EOL to Unix format to avoid any problems (Edit > EOL). You might want to try doing that.

I am using CPanel's text editor (not the styled editor) I find it easier to read like this some times
(2011-01-14, 10:47 AM)MattRogowski Wrote: [ -> ]Enabling HTML won't work simply because it's not HTML. If you try putting \n in a PM, enable HTML in PMs, and it won't turn it into a new line.

@K1LL3RCL0WN what code are you using to insert the PM?? In MySupport I have a function to send a PM, the language string has multiple lines in that, and it doesn't show \n anywhere.
Can you share this with me ? Smile
Inbox?

(2011-01-14, 10:47 AM)MattRogowski Wrote: [ -> ]Enabling HTML won't work simply because it's not HTML. If you try putting \n in a PM, enable HTML in PMs, and it won't turn it into a new line.

@K1LL3RCL0WN what code are you using to insert the PM?? In MySupport I have a function to send a PM, the language string has multiple lines in that, and it doesn't show \n anywhere.


Think i've got it now Smile
Thanks for your help i will release what i have made in a moment Big Grin
Change

"message" => $db->escape_string($message),

to just

"message" => $message,

The datahandler does the escaping for you.
(2011-01-14, 01:07 PM)MattRogowski Wrote: [ -> ]Change

"message" => $db->escape_string($message),

to just

"message" => $message,

The datahandler does the escaping for you.

That is what i did do! Big Grin