Send email of new article

I have set up a subscriber module in my blog and want to send out an email to the subscribers of a new article and new comment. How would I do this and is it possible?

«1

Réponses

  • Hello,
    What is your module alike ?
    Is it a plugin or a script of yours included in your theme's template?

    How would I do this ?

    1. You can use an external email service and only include the form inside your theme
    2. create a plugin , or use one that might be avalaible at https://ressources.pluxopolis.net/banque-plugins/index.php?all_versions&grille
    3. propose to your visitor to use the RSS links

    is it possible?

    It is , but i do not think anything has been develloped yet as described.

    Welcome to PluXml


    Cordialement,
    gcyrillus , simple membre du forum et utilisateur de pluxml

    Mon site PluXml: https://re7net.com | Plugins: https://ressources.pluxopolis.net/banque-plugins/index.php?all_versions | demos sur free http://gcyrillus.free.fr/new | Thèmes: tester et télécharger @ https://pluxthemes.com
    Indiquez [RESOLU] dans le titre de votre question une fois le soucis réglè, Merci

  • afosterafoster Member

    Thank you for your quick response.
    -My module is one I put together from another blog I was using. The problem with it is that I have to generate the file to send the email instead of sending the email automatically.
    -I have looked at the plugins and found the plugin plxMyMailComment which works fine except that I have to enter the email address to send to in the configuration module. I would like it to send it to a list of subscribers that are in a txt file. As to creating my own plugin, I don't have the coding skills to do that. I can take existing code and tweak it to my liking however. assuming it is open source.

  • 8 sept. modifié

    I'll take a look tonight if the plugin can easily be tweaked to work otherwise. Seems a a good start to me.

    [edit & quickly] hmmm there is more to tweak that i believed


    Cordialement,
    gcyrillus , simple membre du forum et utilisateur de pluxml

    Mon site PluXml: https://re7net.com | Plugins: https://ressources.pluxopolis.net/banque-plugins/index.php?all_versions | demos sur free http://gcyrillus.free.fr/new | Thèmes: tester et télécharger @ https://pluxthemes.com
    Indiquez [RESOLU] dans le titre de votre question une fois le soucis réglè, Merci

  • afosterafoster Member

    I have a send mail file that I can use but I don't know where to place the send email code to ensure that the email goes out when the comment/article is posted.

  • 8 sept. modifié

    Okay so, you are using plxMyMailComment which sends a mail to the author when a comment is posted. Are you okay with this and want to keep thgis functionnality ?

    If i understand well, You also need a subscriber form, store subscription then send an alert to the subscriber every time an article is published ?

    Where are you about in your coding attempts ? Have you modified yet the plugin to respond when a new article is published , did you include the subscibe function or is it a standalone script ?
    if you started anything , where in your code do you need help ?

    from what i see about plxMyMailComment , it is missing :
    1. listening to new publication in administration ($_POST['publish'])
    2. a form on front side for the subscription (a form to include via a hook in your theme files or a fake static page )
    3. a storing system that can be parsed and updated. (xml, json, csv, or whatever filetype you have)


    Cordialement,
    gcyrillus , simple membre du forum et utilisateur de pluxml

    Mon site PluXml: https://re7net.com | Plugins: https://ressources.pluxopolis.net/banque-plugins/index.php?all_versions | demos sur free http://gcyrillus.free.fr/new | Thèmes: tester et télécharger @ https://pluxthemes.com
    Indiquez [RESOLU] dans le titre de votre question une fois le soucis réglè, Merci

  • afosterafoster Member

    I appreciate your help.

    I already have a subscriber form so that is not necessary. I also have a file that sends emails when a new article is posted, but I have to enter the file in the address bar after the article is posted. I would like the email to be automatically sent when the article is posted. In order to do that, I need to know in what pluxml file and where in the file I can place the send email code.

    As for the plxMyMailComment plugin is concerned, it can stay as is except that I need it to send it to subscribers that are in a text file. If that is not possible, then I can probably adapt the same send email code for the article sending but again, I would need to know in what pluxml file and where in the file to place the send email code.

    I hope I have not confused you.

  • 8 sept. modifié

    then it stands in the file article.php in the repertory core/admin/

    You can add an if within the (line 26/27)

    //# Formulaire validé
    if(!empty($_POST)) { # Création, mise à jour, suppression ou aperçu
    // ... pluxml code
    }
    

    something alike

    if(isset($_POST['publish']) {
    /* read you subscriber file and extract mail adresses,  then send your mail alert from here */
    }
    

    Mind that if you modify PluXml files, all modification will be lost if you update the CMS.


    Cordialement,
    gcyrillus , simple membre du forum et utilisateur de pluxml

    Mon site PluXml: https://re7net.com | Plugins: https://ressources.pluxopolis.net/banque-plugins/index.php?all_versions | demos sur free http://gcyrillus.free.fr/new | Thèmes: tester et télécharger @ https://pluxthemes.com
    Indiquez [RESOLU] dans le titre de votre question une fois le soucis réglè, Merci

  • afosterafoster Member

    Thanks for that. Where would I add the code in the comments file as I also want that to be sent to the subscribers.

  • afosterafoster Member

    When adding this code as you suggested starting on line 28
    (if(isset($_POST['publish']) {
    /* read you subscriber file and extract mail adresses, then send your mail alert from here */
    },

    I get an error message that says
    PHP Parse error: syntax error, unexpected '{' in https://domain.com/pluxml/core/admin/article.php on line 28

  • oups, i probably did not pay attention , there is a typo

    if(isset($_POST['publish'])) {
    /* your code here */
    }
    

    For the comment, it will be somewhere right before or after :

            # Hook plugins
            if(eval($this->plxPlugins->callHook('plxMotorAddCommentaire'))) return;
    

    in class.plx.motor.php at function addCommentaire() This file stands in core/lib

    Honnestly, i would not advise to modify PluXml files , these bits of code of yours should be injected via a plugin. Then it can be easily deactivated or updated for maintenance .Integrity of PluXml's code will remain that way.


    Cordialement,
    gcyrillus , simple membre du forum et utilisateur de pluxml

    Mon site PluXml: https://re7net.com | Plugins: https://ressources.pluxopolis.net/banque-plugins/index.php?all_versions | demos sur free http://gcyrillus.free.fr/new | Thèmes: tester et télécharger @ https://pluxthemes.com
    Indiquez [RESOLU] dans le titre de votre question une fois le soucis réglè, Merci

  • afosterafoster Member

    Yes, I agree with you, but as I mentioned my coding skills are not at the level needed to develop a plugin. The plugin for sending an email for the comments works fine but does not allow me to send it to a subscriber list contained in a txt file. I have to manually enter the email addresses of the subscribers into the configuration module of the plugin

  • afosterafoster Member

    An email notification was sent as soon as I posted a test article, so the code that I added in the location you suggested (between line 27-28) works as designed. The only issue is that I can't figure out how to provide a link to the article. The screenshot attached shows what the notification looks like. Where/how can I add code to provide a link to the article?

  • to retriev this new url, you need to move your code to the portion (around line123) inside this portion of code

            if($valid) {
                $plxAdmin->editArticle($_POST,$_POST['artId']);
                header('Location: article.php?a='.$_POST['artId']);
                exit;
            # Si url ou date invalide, on ne sauvegarde pas mais on repasse en mode brouillon
            }
    

    before header('Location: article.php?a='.$_POST['artId']);;

    The url to your new article is then:

    $plxMotor->urlRewrite(PLX_ROOT).$url; 
    

    and the title should be $_POST['title']


    Cordialement,
    gcyrillus , simple membre du forum et utilisateur de pluxml

    Mon site PluXml: https://re7net.com | Plugins: https://ressources.pluxopolis.net/banque-plugins/index.php?all_versions | demos sur free http://gcyrillus.free.fr/new | Thèmes: tester et télécharger @ https://pluxthemes.com
    Indiquez [RESOLU] dans le titre de votre question une fois le soucis réglè, Merci

  • 9 sept. modifié

    After all, the best would be to check if $_SESSION['info'] is set and equal to L_ARTICLE_SAVE_SUCCESSFUL in the beginning of the file and retrieve from there the art title and url to send your mail alerts.


    Cordialement,
    gcyrillus , simple membre du forum et utilisateur de pluxml

    Mon site PluXml: https://re7net.com | Plugins: https://ressources.pluxopolis.net/banque-plugins/index.php?all_versions | demos sur free http://gcyrillus.free.fr/new | Thèmes: tester et télécharger @ https://pluxthemes.com
    Indiquez [RESOLU] dans le titre de votre question une fois le soucis réglè, Merci

  • afosterafoster Member

    I'm a little confused. Here is the code I am entering to send the email. Where in this code would I place the code you suggest for the url and title?

    require 'PHPMailerAutoload.php';
    if(isset($_POST['publish'])) {
    $mail = new PHPMailer;
    $mail->isSMTP(); // Set mailer to use SMTP
    //$mail->Host = 'smtp.gmail.com;smtp.gmail.com'; // Specify main and backup SMTP servers
    $mail->Host = ''smtp.gmail.com'; // Specify main and backup SMTP servers
    $mail->SMTPAuth = true; // Enable SMTP authentication
    $mail->Username = 'afoster@gmail'; // SMTP username
    $mail->Password = 'password,'; // SMTP password
    $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, ssl also accepted
    $mail->Port = 465; // TCP port to connect to
    $mail->From = afoster@gmail';
    $mail->FromName = 'Poolmeister';
    $pollids = "../../newsletter/data.txt";
    $contents = file_get_contents($pollids);
    $cont = explode(',', $contents); // contains number of emails
    foreach ($cont as $item) {
    $mail->addAddress($item); // Add a recipient
    }
    $mail->isHTML(true);
    $mail->SingleTo = true;// if u want to send email to multiple users
    $mail->Subject = 'New Blog Post Notification';
    $mail->Body = '



    Single Extension


    image

    A new article has just been posted to the blog.

    Click the link below and enjoy.
    '.$a.'


    ';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
    echo ' An email notification has been sent to the subscribers';
    }

    //header('Location: subscribe.php');
    header('Location: https://domain.com/myblog/');

  • 9 sept. modifié

    hello,
    from top.php on line 2 you can do instead of article.php line 28 :

    <?php 
        if(isset($_SESSION['info']) && $_SESSION['info'] == L_ARTICLE_SAVE_SUCCESSFUL) {
            // scripts will be included here
        }
    ?>
    

    then add at the beginning of your script (you just posted)

        if(!defined('PLX_ROOT')) exit;  // to avoid to run the script outside PluXml
        $c=$plxAdmin->urlRewrite(PLX_ROOT).$url;
        $a=$title;
    

    Now that you get the title and the url to your newly created article you may finally load your script inside your condition if

    <?php 
        if(isset($_SESSION['info']) && $_SESSION['info'] == L_ARTICLE_SAVE_SUCCESSFUL) {
            include('path/to/your/script.php'); // or copy paste $c;$a;and your script here
        }
    ?>
    

    An include will make it easier to modify your script later.


    Cordialement,
    gcyrillus , simple membre du forum et utilisateur de pluxml

    Mon site PluXml: https://re7net.com | Plugins: https://ressources.pluxopolis.net/banque-plugins/index.php?all_versions | demos sur free http://gcyrillus.free.fr/new | Thèmes: tester et télécharger @ https://pluxthemes.com
    Indiquez [RESOLU] dans le titre de votre question une fois le soucis réglè, Merci

  • afosterafoster Member

    First of all, thank you so much for your patience in helping me accomplish my goal.

    I'm pretty sure that I have followed the instructions you provided in your last message and while the article was posted, no email was received. I am not certain that the email was sent. Here is what I did.

    • Beginning on line 2 of top.php I entered the following code:
      <?php if(isset($_SESSION['info']) && $_SESSION['info'] == L_ARTICLE_SAVE_SUCCESSFUL) { // scripts will be included here } ?>

    • At the top of my email script, I entered the following code:
      if(!defined('PLX_ROOT')) exit; // to avoid to run the script outside PluXml
      $c=$plxAdmin->urlRewrite(PLX_ROOT).$url;
      $a=$title;

    • I then entered the following code near the top of top.php replacing "// scripts will be included here:"
      include('sendarticle_email.php');
      I saved the script I had posted as sendarticle_email.php and placed it in the admin folder.

    • I then wrote an article which was posted and is displayed correctly. However as mentioned, no email was received. Where did I make my mistake? OH, I also removed the script from the article.php file...I assume I was supposed to to that?

  • 9 sept. modifié

    seems fine to me but did you make sure it finds the files ?

    1. require 'PHPMailerAutoload.php';
    2. $pollids = "../../newsletter/data.txt";

    Add an echo as a first line to your included script.

    It can be anything but long enough to be noticed alike : echo'//////////////////// NEW ARTICLE --'.$title.'--'.$url.'/////////////////////';

    If you see this on publishing your newly created article, then it the issue is in your script , did you get any warnings or error message ?

    Also remove the header(location: ..); from your code if you did not , you want to stay on your editing article page ;)

    First of all, thank you so much for your patience in helping me accomplish my goal.

    I was once lucky to have people helping me too :) and i hope to be lucky also next time i need help.


    Cordialement,
    gcyrillus , simple membre du forum et utilisateur de pluxml

    Mon site PluXml: https://re7net.com | Plugins: https://ressources.pluxopolis.net/banque-plugins/index.php?all_versions | demos sur free http://gcyrillus.free.fr/new | Thèmes: tester et télécharger @ https://pluxthemes.com
    Indiquez [RESOLU] dans le titre de votre question une fois le soucis réglè, Merci

  • afosterafoster Member

    Since the code I was using in article.php (which is in core/admin) and the sendarticle_email.php file is also in the same admin folder, would not the paths to PHPMailerAutoload.php and ../../newsletter/data.txt not stay the same?

  • afosterafoster Member

    Apropos of nothing, how do I quote a statement in the forum and also, how do I place any code I post in the same manner that you do?

  • 10 sept. modifié

    Since the code I was using in article.php (which is in core/admin) and the sendarticle_email.php file is also in the same admin folder, would not the paths to PHPMailerAutoload.php and ../../newsletter/data.txt not stay the same?

    You are right, it should not be an issue if it worked.

    Did you test echo 'something'; and by the way, are you using pluxml 5.8.16 or à prior version ?

    Apropos of nothing, how do I quote a statement in the forum and also, how do I place any code I post in the same manner that you do?

    The forum understands the markdown format.
    http://fr.wikipedia.org/wiki/Markdown this is what i use :)


    Cordialement,
    gcyrillus , simple membre du forum et utilisateur de pluxml

    Mon site PluXml: https://re7net.com | Plugins: https://ressources.pluxopolis.net/banque-plugins/index.php?all_versions | demos sur free http://gcyrillus.free.fr/new | Thèmes: tester et télécharger @ https://pluxthemes.com
    Indiquez [RESOLU] dans le titre de votre question une fois le soucis réglè, Merci

  • afosterafoster Member
    10 sept. modifié

    I must have missed it...where would I place echo 'something'? I know I have to change the something.

    Also, could it have something to do with this code?

    <?php if(isset($_SESSION['info']) && $_SESSION['info'] == L_ARTICLE_SAVE_SUCCESSFUL) { include('sendarticle_email.php'); } ?>

    I forgot to mention that I am using version 5.8.15

  • I must have missed it...where would I place echo 'something'? I know I have to change the something.

    Sorry about confusing you

    Also, could it have something to do with this code?
    <?php if(isset($_SESSION['info']) && $_SESSION['info'] == L_ARTICLE_SAVE_SUCCESSFUL) { include('sendarticle_email.php'); } ?>

    yes, you can put the echo something on the first line of your included file. it will demonstrate it is loaded ... or not.

    I forgot to mention that I am using version 5.8.15

    okay, it's fine


    Cordialement,
    gcyrillus , simple membre du forum et utilisateur de pluxml

    Mon site PluXml: https://re7net.com | Plugins: https://ressources.pluxopolis.net/banque-plugins/index.php?all_versions | demos sur free http://gcyrillus.free.fr/new | Thèmes: tester et télécharger @ https://pluxthemes.com
    Indiquez [RESOLU] dans le titre de votre question une fois le soucis réglè, Merci

  • afosterafoster Member

    Come to find out that the email script is not sending out the email...the article is being posted however. I don't understand how that is possible as it is the same code that I placed in the article.php file which is sending out the email. Maybe I can't accomplish my goal.

  • Maybe you have a typo in your new scripts , there should not be differences.


    Cordialement,
    gcyrillus , simple membre du forum et utilisateur de pluxml

    Mon site PluXml: https://re7net.com | Plugins: https://ressources.pluxopolis.net/banque-plugins/index.php?all_versions | demos sur free http://gcyrillus.free.fr/new | Thèmes: tester et télécharger @ https://pluxthemes.com
    Indiquez [RESOLU] dans le titre de votre question une fois le soucis réglè, Merci

  • afosterafoster Member
    11 sept. modifié

    I checked again and there are no typos. I copy/pasted the email script that was working, copy/pasted the code you provided and just added the path to the email script. Perhaps I did not read your directions correctly and the paths to the subscriber list is correct. Here is a schematic of the pluxml folder as I have it set up. I am only including the relevant folders.

    Pluxml
    newsletter
    core
    admn
    top.php
    article.php
    sendemail.php

    Let me know if you see any problems, but at this point it doesn't look as if I will be able to set it up with a link to the article.

  • 11 sept. modifié

    Sounds fine but i will propose you something else.

    PluXml comes with PHPMailer , let's try to use it.

    modification to do :
    1. core/admin/top.php
    replace (somewhere around line 148-150):

                plxMsg::Display();
    

    with

                    if(isset($alertNewArticle)) echo $alertNewArticle;
                plxMsg::Display();
    
    1. core/admin/article.php
      replace (somewhere around line 230-232):
    # On inclut le header
    include __DIR__ .'/top.php';
    

    with

    if(isset($_SESSION['info']) && $_SESSION['info'] == L_ARTICLE_SAVE_SUCCESSFUL) { include('sendemail.php'); } 
    # On inclut le header
    include __DIR__ .'/top.php';
    

    Then sendemail.php becomes :

    (do not forget to reset all $mail->values to connect to your smtp

    <?php if(!defined('PLX_ROOT')) exit; 
    
    // use PluXml archive to load PHPMailer or comment next lines 
    ////////////////////////////////////////// s
        use PHPMailer\PHPMailer\PHPMailer;
        use PHPMailer\PHPMailer\SMTP;
        use PHPMailer\PHPMailer\OAuth;
        use League\OAuth2\Client\Provider\Google;
    
        require PLX_CORE.'vendor/autoload.php';
    /////////////////////////////////////////// e
    
    //  or use your own PHPMailer and uncomment next line
    ////////////////////////////////////////// s
    //      require 'PHPMailerAutoload.php'; 
    ////////////////////////////////////////// e
    
    ///////// get link for the new article /////////
            $a ='<a href="'.$plxAdmin->urlRewrite(PLX_ROOT).$url.'">'.$title.'</a>';
    
            $mail = new PHPMailer();
            $mail->isSMTP(); // Set mailer to use SMTP
            $mail->Host =' ' ; // Specify main and backup SMTP servers
            $mail->SMTPAuth = true; // Enable SMTP authentication
            $mail->Username = ' '; // SMTP username
            $mail->Password = ' '; // SMTP password
            $mail->SMTPSecure = ' '; // Enable TLS encryption, ssl also accepted
            $mail->Port =  ; // TCP port to connect to
            $mail->From = ' ';
            $mail->FromName = ' ';
            $pollids = "../../newsletter/data.txt";
            $contents = file_get_contents($pollids);
            $cont = explode(',', $contents); // contains number of emails
            foreach ($cont as $item) {
                $mail->addAddress($item); // Add a recipient
            }
            $mail->isHTML(true);
            $mail->SingleTo = true;// if u want to send email to multiple users
            $mail->Subject = 'New Blog Post Notification';
            $mail->Body = 'New article created on '.plxUtils::strCheck($plxAdmin->aConf['title']).' see:  '.$a;
            $mail->AltBody = 'New article created on '.plxUtils::strCheck($plxAdmin->aConf['title']).' see:  '.$title.' @ '.$url;
            if(!$mail->send()) {
                $alertNewArticle= '<p id="msg"> Message could not be sent.<br>
                 Mailer Error: ' . $mail->ErrorInfo .'</p>';
                } else {
                $alertNewArticle = '<p id="msg" class="alert green"> An email notification has been sent to the subscribers</p>';
            }
    

    It can load phpMailer provided with PluXml
    It retrieves title and url of the newly created article.

    I tested it and it calls and tries to send mails as supposed to (my phpmailer configuration doesn't work, probably because just tested it on local)

    Hope that will finally work for you ;)


    Cordialement,
    gcyrillus , simple membre du forum et utilisateur de pluxml

    Mon site PluXml: https://re7net.com | Plugins: https://ressources.pluxopolis.net/banque-plugins/index.php?all_versions | demos sur free http://gcyrillus.free.fr/new | Thèmes: tester et télécharger @ https://pluxthemes.com
    Indiquez [RESOLU] dans le titre de votre question une fois le soucis réglè, Merci

  • afosterafoster Member
    11 sept. modifié

    I am getting the following error message when trying to access the admin module to write a new article:

    Fatal error :
    type : 8
    message : Undefined variable: alertNewArticle
    file : C:\xampp\htdocs\pluxml\core\admin\top.php
    line : 149

    UPDATE...

    I changed the code in top.php to the following and it seems to work. Let me know if I should not do this.

    $alertNewArticle ='';
    echo $alertNewArticle;
    plxMsg::Display();

  • 11 sept. modifié

    hmmm, top.php modification becomes:

    see below at https://forum.pluxml.org/discussion/comment/65452/#Comment_65452


    Cordialement,
    gcyrillus , simple membre du forum et utilisateur de pluxml

    Mon site PluXml: https://re7net.com | Plugins: https://ressources.pluxopolis.net/banque-plugins/index.php?all_versions | demos sur free http://gcyrillus.free.fr/new | Thèmes: tester et télécharger @ https://pluxthemes.com
    Indiquez [RESOLU] dans le titre de votre question une fois le soucis réglè, Merci

  • afosterafoster Member

    I thought your directions stated that the code below was to be inserted into the article.php file. Am I mistaken?

    if(isset($_SESSION['info']) && $_SESSION['info'] == L_ARTICLE_SAVE_SUCCESSFUL) {
    include('sendemail.php');
    echo $alertNewArticle;
    }

    On inclut le header

    include DIR .'/top.php';

Connectez-vous ou Inscrivez-vous pour répondre.