Fork me on GitHub
Current releases are 2.1.1 (2 Aug 2014) and 2.0.18.13 (5 Aug 2014)
Ready for 2.1? Find out if your favorite plugins are compatible.
The 2.0 branch will no longer receive updates after Dec 2014.

Add Discussion Subject in Email Body

edited March 2011 in Vanilla 2.0 Help
This discussion is related to the EMailDiscussion addon.
How can I add the discussion subject in the email body?

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... :)
    DavidShine
  • 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.

    DavidShine
  • 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!

    DavidShine
  • 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.

    DavidShine
  • 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

    DavidShine
  • 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 Jester 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();
        }
    }
    
  • 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 ☯ hasta luego :) In-Flight MVP
    edited May 18

    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 }

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

  • DenisSDenisS
    edited May 19

    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 Jester MVP

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

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

    peregrine
  • vrijvlindervrijvlinder Jester MVP

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

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

    peregrine
  • DenisSDenisS
    edited May 19

    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
    edited May 19

    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!";

  • peregrineperegrine ☯ hasta luego :) In-Flight MVP

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

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

  • DenisSDenisS
    edited May 19

    This line is in > conf/config-defaults.php

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

  • vrijvlindervrijvlinder Jester MVP
    edited May 19

    $Configuration['Garden']['Email']['MimeType']= 'text/html'; No don't have, should i put in?

    yes change plain to html , in the config.php

  • peregrineperegrine ☯ hasta luego :) In-Flight MVP
    edited May 19

    don't ever change the config-defaults.php (it is the base default). it will get overwritten anyway next time you update the source. that is essentially changing the core, which you do NOT want to do.

    you should add and change things ONLY in config.php

    add any new defintions you want in conf/locale.php if they don't yet exist.

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

    vrijvlinder
  • vrijvlindervrijvlinder Jester MVP

    Yes please keep up Denis this is not the first time you do this.

    Read this again http://vanillaforums.org/discussion/comment/208183/#Comment_208183

    I asked if it was in the config.php not elsewhere.

    If it is not in the config.php you add it.

    peregrine
  • No it's not working the message is still the same:

    " A new message has been posted by deniss. It can be accessed at Link " ( No Title )

    I'm i was getting mixed up with the message to ADMIN, I set up 2 basic Members to test it today and got the above message.

    I have put the code you done in , i have put > $Configuration['Garden']['Email']['MimeType']= 'text/html'; < in the config.php I have not put > $Definitions as a Email story < in Local because i think it needs more code added. eg: $Definition["GuestModule.Message"] = hello how you.

    Thanks for you time but It's something that i think is important to send the Title to generate interest.

Sign In or Register to comment.