HTML & Private Messages

Started by Texan78, August 21, 2012, 09:46:26 PM

Previous topic - Next topic

Texan78

Hello,

Is it possible to use HTML in private messages?

I have a mod that upon registration sends the member a PM with information about their membership.

The message is in my language file and formatted in HTML. In my test I have noticed when the member gets it the HTML is not parsed.

Is there a setting to allow HTML in PM that I am missing?

-Thanks

JBlaze

If you're sending the PM via an Admin account, you can use the [html][/html] tags. Simply insert the HTML you want to use between the two tags, and it should parse.
Jason Clemons
Former Team Member 2009 - 2012

Texan78

No that doesn't work. It doesn't send it from the Admin account persay. It is a automated message and the message is in my language file.

I add your suggestion like so

$txt['fb_password_welcome'] = '[html]<p>yada yada yada some text here .</p> <p>yada yada yada some more text here</p> <p>yada yada yada more information text here</p> <p>same ol same ol you get the message</p><br /><br />Regards,<br />Forum Staff.[/html]';

That doesn't work, it renders it like it did before adding the html bbc tag.

MrPhil

The PM system supports BBCode. Is that inadequate for what you want to do? Or is it not properly parsing BBCode for some reason? In your example, I don't see anything that couldn't be done with BBCode (are you trying to do other things?). That it's coming from a file rather than being typed in, may mean that you will have to define a new BBCode tag for [p] (there is already a [br]) to get the level of formatting control you want.

Texan78

How do you go about defining a new bbc tag?

-Thanks

Texan78

The tag can only be used by the "Administrator" for security reasons. It is sending it by a user called Admin, but not the "Active Administrator" so that is probably why it is not working correctly. If I use the  tag in a post by the "Active Administrator" I am able to use html no problems as the "Administrator" when logged in as you can see in the screen shot below.



Looks like the problem is when it sends the PM it sends it as "Administrator" but as a Guest. As you can see it doesn't parse any of the HTML even with the  bbc tag which is in it as you can see in the language file screen shot.







Here is the code that actually sends the PM. As you can see it is set to send from the Administrator. But for some reason it sends it as Guest.


      //Set up the pm
    $title = 'Facebook Forum Password'; //the title of the pm
    $message = sprintf($txt['fb_password_welcome'], $password); //the body of the pm
   
    $pmfrom = array(
        'id' => 0, //user id where the pm is from
        'name' => 'Administrator', //name of the user who the pm is from
        'username' => 'Administrator', //username of the user who the pm is from
    );
       
    $pmto = array(
        'to' => array($memberID),// array of ids to send the pm to
        'bcc' => array()//bbc array
    );

    //Now send it
    sendpm($pmto, $title, $message , 0, $pmfrom);

updateMemberData($memberID,
        array(
    'fbname' => $fb_object->user_info_fbname,
        'fbid' => $fb_object->user_info_fbid,
    )
    );


Any suggestions or ideas?

-Thanks







SA™

Quote
//Set up the pm
$title = 'Facebook Forum Password'; //the title of the pm
$message = sprintf($txt['fb_password_welcome'], $password); //the body of the pm
   
$pmfrom = array(
    'id' => 0, //user id where the pm is from
    'name' => 'Administrator', //name of the user who the pm is from
    'username' => 'Administrator', //username of the user who the pm is from
);
       
$pmto = array(
    'to' => array($memberID),// array of ids to send the pm to
    'bcc' => array()//bbc array
);
   
//Now send it
sendpm($pmto, $title, $message , 0, $pmfrom);
      
updateMemberData($memberID,
    array(
         'fbname' => $fb_object->user_info_fbname,
    'fbid' => $fb_object->user_info_fbid,
    )
);

the zero needs to be a member id
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Texan78

Thank you SA, that did the trick and works great for resolve that.

BUT, I am still having issues with it parsing HTML even as the registered Administrator.



So is it not possible to use BBC or HTML in PM?

Works fine in posts, just not in PM.

Any ideas or suggestions?

-Thanks

SA™

maybe add
$message = parse_bbc($message);
after
$message = sprintf($txt['fb_password_welcome'], $password); //the body of the pm
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Texan78

Thanks for the response. I inserted the code...

  //Set up the pm
    $title = 'Facebook Forum Password'; //the title of the pm
    $message = sprintf($txt['fb_password_welcome'], $password); //the body of the pm
    $message = parse_bbc($message);


It still doesn't parse the bbc

I tested something by sending a normal PM to a test member I have set up using the  bbc tag as you can see. If you look in the preview it doesn't parse the html with the tag in a PM. If I add it in a post it works fine.

Is there a way to parse html in a PM?



-Thanks!



MrPhil

PMs normally do parse BBCode (when displayed by the recipient). I've sometimes noticed odd behavior in the email that gets sent with the PM, but apparently not consistently enough to open a bug report. All I can think of is that when your PM source is from the database rather than being typed in, the processing path is different enough that the HTML is produced too early and goes through the "sanitizing" of < > &, which disables HTML. Can you send a PM with exactly the same BBCode manually typed in, and it works? Also, does the "html" BBCode tag work in those circumstances? In all cases, the page source (browser HTML) shows &lt; &gt; &amp; instead of < > &? Once you've got BBCode/HTML processing squared away, you can look at adding new BBCode tags (if needed).

I will send you a PM with HTML just to confirm.

Texan78

Quote from: MrPhil on August 22, 2012, 04:55:13 PM
All I can think of is that when your PM source is from the database rather than being typed in, the processing path is different enough that the HTML is produced too early and goes through the "sanitizing" of < > &, which disables HTML.

The PM I am trying to send is stored in a language file and then called to the PM this way...

  //Set up the pm
    $title = 'Facebook Forum Password'; //the title of the pm
    $message = sprintf($txt['fb_password_welcome'], $password); //the body of the pm
    $message = parse_bbc($message);



Quote from: MrPhil on August 22, 2012, 04:55:13 PMCan you send a PM with exactly the same BBCode manually typed in, and it works? Also, does the "html" BBCode tag work in those circumstances?

Yes, if you look at the screen shot below I am logged in as Admin and the BBC code works correctly. But the HTML BBC code doesn't work in PM, but it does work in topics. That is what is really ironic is I can parse HTML with the bbc html tag in a post but not in a PM.

Really the only BBC tag I would need is the paragraph tag <p> which IMO I would think would already exsist. Would make formatting a little easier, but then again why would you need in in posts when you can just go space space...LoL Would only be needed in times like this.

If you look in the text field below, it is wrapped in HTML BBC tags, but it it doesn't parse it. Like I said, it works in posts and I have screen shots posted earlier showing this. Very strange IMO.




-Thanks

Texan78

Ok, I am making progress. I went and just changed the HTML out to
 
tags. Then I had to add something to the code.

Had to add this.

$message = preg_replace('~<br(?: /)?' . '>~', "\n", $message);
    $message = un_htmlspecialchars($message);


To this and I was able to parse the BBC.

   //Set up the pm
    $title = 'Facebook Forum Password'; //the title of the pm
    $message = sprintf($txt['fb_password_welcome'], $password); //the body of the pm
    $message = parse_bbc($message);
    $message = preg_replace('~<br(?: /)?' . '>~', "\n", $message);
    $message = un_htmlspecialchars($message);


Now the only problem I have left is it doesn't parse the tag. When it parses it shows <strong>text</strong> instead.

This is what is in the language file.

Here is your password for the forum [b]%1$s[/b]

This is how it is displayed



Any ideas or suggestions?

-Thanks!

MrPhil

So <strong> is actually sent to the browser as &lt;strong&gt; (disabled)? It sounds like somehow you're calling parse_bbc too early, before SMF sanitizes posts or PMs by disabling HTML tags. I'm not sure you should be calling parse_bbc yourself -- doesn't PM processing do that for you at the appropriate time? That's all I can think of at this point. I'll post back if I think of anything else.

Texan78

So I removed the $message = parse_bbc($message); from the code and it works perfectly now.

It was just strange that [br] was parsed but [b] wasn't with that inserted.

All is good now. Thank you to everyone for their suggestions and help.

Thanks!

Advertisement: