Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Add Discussion Subject in Email Body

edited March 2011 in Vanilla 2.0 - 2.8
How can I add the discussion subject in the email body?
«1

Comments

  • I edited the last line of this section of the default.php file so it put the title of the post in the email body and removed the actual contents of the forum post itself as i did not want them there....



    class EMailSubscribe extends Gdn_Plugin {

    public function PostController_AfterDiscussionSave_Handler(&$Sender){
    $Session = Gdn::Session();
    $UserName = $Session->User->Name;
    $ActivityHeadline = $UserName . " has started a new discussion";

    $DiscussionID = $Sender->EventArguments['Discussion']->DiscussionID;
    $DiscussionName = $Sender->EventArguments['Discussion']->Name;
    $CategoryID = $Sender->EventArguments['Discussion']->CategoryID;
    $Story = "Entitled..." . $Sender->EventArguments['Discussion']->Name;





    Now my emails basically look like...

    "MikeBerry has started a new discussion....

    Entitled.... How to fix something"
  • Yeah, that's just what I wanted, thank you!
  • Hi @bezzoh

    Could you possible supply the code for your whole default.php, or at least the bit that displays the text in the email body? Think its wrapped around $Message parameter. I'm trying to figure out what the parameter is to include the discussion title in the email body, but I'm struggling to work out your example above, as its quite different from my file... I've tried $DiscussionName and $Story so far.

    thanks,
  • I cant paste the whole default.php due to character limitations of this forum, however i have pasted from the top up to the change i mentioned above to achieve the goal I was after...




    <?php if (!defined('APPLICATION')) exit();

    /**
    * Changelog
    * 0.1.1
    * * fixed bug sending email to deleted users
    * 0.1.22
    * * fix typo
    * 0.1.30
    * * enforcing permissions - users can't subscribe to Categories that they don't have Vanilla.Discussions.View permission
    * 0.1.31
    * * reestablish the "Subscribe everyone to everything" and improve it with "everything they can view" via some SQL juggling.
    * 0.1.32
    * * fix bug where I left a die() in the code.
    * 0.1.33
    * * finally understood how categories and permissions work, despite the lack of documentation in the code.
    */

    $PluginInfo['EMailSubscribe'] = array(
    'Description' => 'Enables users to subscribe to receive e-mails when new posts in different Categories are posted',
    'Version' => '0.1.33',
    'RequiredApplications' => NULL,
    'RequiredTheme' => FALSE,
    'RequiredPlugins' => FALSE,
    'HasLocale' => FALSE,
    'Author' => 'Catalin David',
    'AuthorEmail' => 'c.david@jacobs-university.de'
    );


    class EMailSubscribe extends Gdn_Plugin {

    public function PostController_AfterDiscussionSave_Handler(&$Sender){
    $Session = Gdn::Session();
    $UserName = $Session->User->Name;
    $ActivityHeadline = $UserName . " has started a new discussion";

    $DiscussionID = $Sender->EventArguments['Discussion']->DiscussionID;
    $DiscussionName = $Sender->EventArguments['Discussion']->Name;
    $CategoryID = $Sender->EventArguments['Discussion']->CategoryID;
    $Story = "Entitled..." . $Sender->EventArguments['Discussion']->Name;

  • I think your talking about the EmailSubscribe plugin, but this discussion originally started asking about the EmailDiscussion plugin which allows an admin to email a new discussion to all users in the forum. Hence why i was a bit confused looking at your code last week... :)
  • As i was really keen to use this feature I've looked up some php code to do it.
    After line 53 ish of the default.php you shoudl have something similar to:
    $Subject = "blah blah blah";
    Add underneath:
    $PostTitle = $_REQUEST['Discussion/Name'];
    $PostContent = $_REQUEST['Discussion/Body'];

    Within the email section below that (contained within the $Message container), you can then reference $PostTitle and $PostContent to make the discussion title and body copy appear as appropriate.
    Works well for me anyway... :)
  • DenisSDenisS My brain hurts Buriram ✭✭

    Thanks Bezzoh, very much this was the only solution to stopping PHP code being sent in the emails when WYSIWYG plugins are installed. Save me a sleepless night.

  • DenisSDenisS My brain hurts Buriram ✭✭

    Please help I'm at total loss where to find this problem: where do i find the code???
    No 1::
    admin started a discussion. email testing --- Follow the link below to check it out: http://www.korat-expatsforum.services-thai.com/discussion/53/email-testing Have a great day!
    I recive this without the link highlighted on one Forum then on the other forum I receive the one below which is correct >

    No 2::
    admin has started a new discussion

    Entitled...Case of Central World arson to be ruled in late March


    Follow the link below to check it out:
    http://www.surin-expatsforum.services-thai.com/discussion/6/case-of-central-world-arson-to-be-ruled-in-late-march

    Have a great day!

  • DenisSDenisS My brain hurts Buriram ✭✭

    Please help I'm at total loss where to find this problem: where do i find the code???

    This was solved this morning: Thanks to help from Vrijvlinder.

  • DenisSDenisS My brain hurts Buriram ✭✭

    I think this is the code thats tell what to send out in EMailDiscussion/default.php:

    <

    p>A new message has been posted by ' . $Name . '. It can be accessed at Link
    If i wanted to ad the "Discussion Title" because this is what would make members click the link. How would add "Discussion Title" ? I want to use this not just as a message email but to generate visits.
    I have tried many ways but just keep coming up with line errors. I only been learning PHP/ HTML for about 4 weeks so need some help.
    Thanks, Denis

  • DenisSDenisS My brain hurts Buriram ✭✭

    I never did get this working to sen Title so I tried again today but get the error> Parse error: syntax error, unexpected T_STRING in /home3/hannahas/public_html/isaan-expatsforum/plugins/EMailDiscussion/default.php on line 56

    This the code:

    '. $Subject .'
    $PostTitle = $_REQUEST['Discussion/Name'];


    A new message has been posted by ' . $Name . '.$PostTitle .' It can be accessed at Link

    where am I going wrong. I really want to send Tiles

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    Try this

    <?php if (!defined('APPLICATION')) exit();
    
    $PluginInfo['EMailDiscussion'] = array(
       'Description' => 'Allows users that have certain permissions to mark a discussion as an announcement and have it sent to everybody',
       'Version' => '0.2',
       'RequiredApplications' => NULL,
       'RequiredTheme' => FALSE,
       'RequiredPlugins' => FALSE,
       'RegisterPermissions' => array('Plugins.EMailNotification.Send'),
       'HasLocale' => FALSE,
       'Author' => "Catalin David",
       'AuthorEmail' => 'c.david@jacobs-university.de'
    );
    
    class EMailDiscussion extends Gdn_Plugin {
    
        public function PostController_BeforeFormButtons_Handler($Sender) {
            $Session = Gdn::Session();
            if($Session->CheckPermission('Plugins.EMailNotification.Send')) {
                if (in_array($Sender->RequestMethod, array('discussion', 'editdiscussion'))) {
                    $FormValues = $Sender->EventArguments['FormPostValues'];
                    echo "<ul class='PostOptions'><li>";
                    echo $Sender->Form->CheckBox('EMailDiscussion', T('EMail this discussion'), array('value' => '1'));
                    echo "</li></ul>";
                }
            }
        }
    
        public function PostController_AfterDiscussionSave_Handler($Sender) {
            $Session = Gdn::Session();
            $UserName = $Session->User->Name;
                $ActivityHeadline = $UserName . " has started a new discussion";
            $EMailCheckBox = $Sender->Form->GetFormValue('EMailDiscussion', '');
            $DiscussionID = $Sender->EventArguments['Discussion']->DiscussionID;
            $DiscussionName = $Sender->EventArguments['Discussion']->Name;
                $CategoryID = $Sender->EventArguments['Discussion']->CategoryID;
                $Story = "Entitled..." . $Sender->EventArguments['Discussion']->Name;
    
    
    
    
    
    
            $SQL = Gdn::SQL();
            if($EMailCheckBox == '1') {
                //send an e-mail to everybody
                //1) select all users' e-mail address
                $SqlEmails = $SQL->Select('EMail','','EMail')
                ->From('User')
                ->Get();
                $Emails = array();
                while($Email = $SqlEmails->NextRow(DATASET_TYPE_ARRAY)) {
                    $Emails[] = $Email['EMail'];
                }
    
                //2) get current user
                $Session = Gdn::Session();
                $Name = $Session->User->Name;
    
                //3) mail
                //bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
                $Subject = "Important topic on " . $_SERVER['HTTP_HOST'] ;
    
                $Message = '
    <html>
    <head>
      <title>'. $Subject .'</title>
    </head>
    <body>
      <p>A new message has been posted by ' . $Name . '. It can be accessed at <a href="http://'. $_SERVER['HTTP_HOST'] .'/index.php?p=/discussion/'. $DiscussionID .'">Link</a> 
      </p>  
    </body>
    </html>
    ';
    
                $Headers = 'MIME-Version: 1.0' . "\r\n".
                           'Content-type: text/html; charset=iso-8859-1' . "\r\n".
                           'From: webmaster@kwarc.info' . "\r\n" .
                        'Reply-To: webmaster@kwarc.info' . "\r\n" .
                        'X-Mailer: PHP/' . phpversion();
    
                foreach($Emails as $Email) {
                    mail($Email, $Subject, $Message, $Headers);
                }
            }
        }
    
        public function Setup() {
            $SQL = Gdn::SQL();
            $Database =  Gdn::Database();
    
            $PermissionModel = Gdn::PermissionModel();
            $PermissionModel->Database = $Database;
            $PermissionModel->SQL = $SQL;
    
            // Define some global addon permissions.
            $PermissionModel->Define(array(
             'Plugins.EMailNotification.Send'
          ));
    
          // Set the initial administrator permissions.
          $PermissionModel->Save(array(
             'RoleID' => 16,
             'Plugins.EMailNotification.Send' => 1
          ));
    
          // Make sure that User.Permissions is blank so new permissions for users get applied.
          $SQL->Update('User', array('Permissions' => ''))->Put();
        }
    }
    
  • DenisSDenisS My brain hurts Buriram ✭✭

    I don't want Member to use the emaildiscussion plugin only Admin or Moderators and only send discussion title, eg: " Border insecurity mounts as tourist visa abuse is targeted " Is this what this will do?
    I did put this code in and got this error:
    Parse error: syntax error, unexpected $end in /home3/hannahas/public_html/isaan-expatsforum/plugins/EMailDiscussion/default.php on line 88

  • peregrineperegrine MVP
    edited May 2014

    Parse error: syntax error, unexpected $end in /home3/hannahas/public_html/isaan-expatsforum/plugins/EMailDiscussion/default.php on line 88

    you most likely didn't cut and paste the code correctly.

    check to make sure you have all the closing brackets }

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • DenisSDenisS My brain hurts Buriram ✭✭
    edited May 2014

    Thanks peregrin and vrijvlinder. Yes must have been me somehow not pasteing correctly. I tried again today and it sends the discussion title now. but it sends the full link address not just "link" and the message is different to what's in the code, how?

    Recieved today > deniss started a discussion.

    On the Thai Expats facebook page we get a lot of invitations

    Follow the link below to check it out:
    http://isaan-expatsforum.services-thai.com/discussion/1863/on-the-thai-expats-facebook-page-we-get-a-lot-of-invitations

    Have a great day!


    Received before: > A new message has been posted by deniss
    It can be accessed at Link

    In the code it's still the same, where does it get the message and how can i edit it?

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    ok you need to see in your config.php if you have

    $Configuration['Garden']['Email']['MimeType']= 'text/html';

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    the message is different to what's in the code, how?

    That message is in the locale $Definitions as a Email story.

  • DenisSDenisS My brain hurts Buriram ✭✭
    edited May 2014

    ok you need to see in your config.php if you have

    $Configuration['Garden']['Email']['MimeType']= 'text/html';

    No don't have, should i put in?

  • DenisSDenisS My brain hurts Buriram ✭✭
    edited May 2014

    vrijvlinder: That message is in the locale $Definitions as a Email story. not in mine

    /conf/locale.php >>>>>
    <?php if (!defined('APPLICATION')) exit();

    $Definition['Howdy, Stranger!'] = 'Welcome to Thai Expats!';

    $Definition["GuestModule.Message"] = "If you want to take part in the discussions, sign in or apply for membership below!";

  • its the same old story add them if they are not there!

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.