e-mail the comment

In this board you can talk about general questions about phpMyFAQ

Moderator: Thorsten

Post Reply
sergey.khodjamirian
Posts: 35
Joined: Wed Aug 09, 2006 11:36 am

e-mail the comment

Post by sergey.khodjamirian »

Hi,

Could someone please help me alter the script a little. I want it so that:

When a user clicks submit comment, when making a comment to an entry, as well as putting the comment at the bottom of the display entry page, an e-mail is sent to the admin with the comment and the question ID or link (or something similar).

I have asked a friend to try and alter the code (he knows some php), but I thought that the creators would probably have a quick solution to it.

Thanks!

Sergey
matteo
Posts: 572
Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy

Re: e-mail the comment

Post by matteo »

Hi Sergey,
sergey.khodjamirian wrote:I have asked a friend to try and alter the code (he knows some php), but I thought that the creators would probably have a quick solution to it.
everything is already in place, see savequestion.php ;).

Locate these lines below in savecomment.php:

Code: Select all

...
    $result = $db->query("INSERT INTO ".SQLPREFIX."faqcomments (id_comment, id, usr, email, comment, datum, helped) VALUES (".$db->nextID(SQLPREFIX."faqcomments", "id_comment").", ".$id.", '".$comment_by_user."', '".$comment_by_mail."', '".$comment."', ".time().", '".$helped."')");

    $tpl->processTemplate ("writeContent", array(
...
and change them to read these lines below:

Code: Select all

...
    $result = $db->query("INSERT INTO ".SQLPREFIX."faqcomments (id_comment, id, usr, email, comment, datum, helped) VALUES (".$db->nextID(SQLPREFIX."faqcomments", "id_comment").", ".$id.", '".$comment_by_user."', '".$comment_by_mail."', '".$comment."', ".time().", '".$helped."')");

    $commentMail =  "User: ".$comment_by_user.", mailto:".$comment_by_mail."\n".
                    "New comment posted on: http://".$_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"]."?action=artikel&cat=".$cat."&id=".$id."&artlang=".$lang.
                    "\n\n".
                    wordwrap($_POST["comment"], 72);

    $additional_header = array();
    $additional_header[] = 'MIME-Version: 1.0';
    $additional_header[] = 'Content-Type: text/plain; charset='. $PMF_LANG['metaCharset'];
    if (strtolower($PMF_LANG['metaCharset']) == 'utf-8') {
        $additional_header[] = 'Content-Transfer-Encoding: 8bit';
    }
    $additional_header[] = 'From: '.'<'.$IDN->encode($comment_by_mail).'>';
    $body = strip_tags($commentMail);
    $body = str_replace(array("\r\n", "\r", "\n"), "\n", $body);
    $body = str_replace(array("\r\n", "\r", "\n"), "\n", $body);
    if (strstr(PHP_OS, 'WIN') !== NULL) {
        // if windows, cr must "\r\n". if other must "\n".
        $body = str_replace("\n", "\r\n", $body);
    }
    mail($IDN->encode($PMF_CONF['adminmail']), $PMF_CONF['title'], $body, implode("\r\n", $additional_header), '-f'.$IDN->encode($comment_by_mail));

    $tpl->processTemplate ("writeContent", array(
...
That's all :).

Regards,
Matteo
phpMyFAQ QA / Developer
Amazon.co.uk Wishlist
sergey.khodjamirian
Posts: 35
Joined: Wed Aug 09, 2006 11:36 am

Post by sergey.khodjamirian »

Matteo, Thank you very much for the help. My friend actually mentioned something similar. So the comment will be sent with the e-mail?
matteo
Posts: 572
Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy

Post by matteo »

Hi Sergey,
yes, you should be able to read the text that the admin will receive here:

Code: Select all

    $commentMail =  "User: ".$comment_by_user.", mailto:".$comment_by_mail."\n".
                    "New comment posted on: http://".$_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"]."?action=artikel&cat=".$cat."&id=".$id."&artlang=".$lang.
                    "\n\n".
                    wordwrap($_POST["comment"], 72); 
As you can see, you have:
  1. The user name and email;
  2. The link to the faq record on which the comment has been submitted;
  3. the text of the comment.
Regards,
Matteo
phpMyFAQ QA / Developer
Amazon.co.uk Wishlist
sergey.khodjamirian
Posts: 35
Joined: Wed Aug 09, 2006 11:36 am

Post by sergey.khodjamirian »

Perfect! Thanks!
matteo
Posts: 572
Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy

Post by matteo »

Hi all,
FYI, this feature request has been commited into PMF 2.0.0 code.

Regards,
Matteo
phpMyFAQ QA / Developer
Amazon.co.uk Wishlist
sergey.khodjamirian
Posts: 35
Joined: Wed Aug 09, 2006 11:36 am

Post by sergey.khodjamirian »

I made this modification. Now what happens is when submit comment is clicked, a blank page shows up with the following in the address:

http://lonvmmldap02/rfpqakb/index.php?a ... avecomment

The comment doesn't get sent to the admin AND it doesn't get added to the bottom of the entry that was commented on.

Is something missing?
matteo
Posts: 572
Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy

Post by matteo »

Hi Sergey,
sergey.khodjamirian wrote:Is something missing?
the hack is working as expected on my server @home so could you kindly configure your server to let PHP print out warning and notice errors (this seems to be the same issue as depicted in viewtopic.php?t=2740)?

Ciao,
Matteo
phpMyFAQ QA / Developer
Amazon.co.uk Wishlist
Post Reply