WebsiteBaker Community Forum
WebsiteBaker Support (2.8.x) => Droplets & Snippets => Topic started by: Argos on November 10, 2010, 01:39:04 PM
-
I tried to implement a function that sends an email notification when a news item is commented. There is a topic that has code, but I can't get it to work. See https://forum.WebsiteBaker.org/index.php/topic,4699.0.html
Ideal would be a droplet that I can just put in the settings of the news module, but code snippet to put in a php file would be okay as well. Can anyone help? Thanks in advance!
-
Hoi Argos,
Can't be done with a droplet in settings.
You need extra code wich mail a warning when and only when a submission is made, therefore the best option is to add that code to submit_comment.php,
search for: around line 121,
// Insert the comment into db
A few lines later, right before the header statement this code can be added.
// Sending the email
$mail_to = 'address@tosendmail.to';
$mail_subject = 'A comment has been made';
$mail_message = 'One newsitem has been commented on this page: '.$wb->page_link($page['link']).'?post_id='.$post_id.' !';
$wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message);
Didn't test it!! but think it'll get you started ;)
Have fun,
John
-
Works right away John, thank you very much! :-D
I'll post a reference in the other topic.
I have edited the snippet to contain a working link and the comment itself:
$mail_to = 'address@tosendmail.to';
$mail_subject = 'A comment has been made';
$mail_message = 'One newsitem has been commented on this page: <a href="'.$wb->page_link($page['link']).'">'.$wb->page_link($page['link']).'</a>
Comment:
'.$comment.'' ;
$wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message);
-
Cool to know I can still make working code without testing ;)
PS Will be incoörporated in articles.
-
Cool to know I can still make working code without testing ;)
I'm jealous :wink:
PS Will be incoörporated in articles.
Nice. Maybe you can use language variables instead of the hardcoded English text lines.
-
will be in settings
adminsettings, use comments? use mail notification?
settings - comments, comment layout template and email template if the above is true
Will be a heap of settings ;)
John
-
Thanks for this Argos and John - this works great, just what I was looking for =)
-Mike
Works right away John, thank you very much! :-D
I'll post a reference in the other topic.
I have edited the snippet to contain a working link and the comment itself:
$mail_to = 'address@tosendmail.to';
$mail_subject = 'A comment has been made';
$mail_message = 'One newsitem has been commented on this page: <a href="'.$wb->page_link($page['link']).'">'.$wb->page_link($page['link']).'</a>
Comment:
'.$comment.'' ;
$wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message);
-
@pcwacht
Any progress on the articles module yet?
What i saw à while ago was very promising, i have made quite some additions to the news3,5 newsmodule, I will include the commentnotification and send you a version
-
Please do.
Artcles is still an ongoing work in progress. The progress is being slowed down cause of the promised 2.9, , allso I was/am bizzy with some other modules needed for work. And work itself.
Allso had some operation on my hip last september, I needed a new one wich slowed me down as well.
Am coding articles when I have some spare time left wich is rarely the case ;)
John
-
you will receive it today
-
Hello,
For some time I added this code in my modules/news/submit_comment.php
$mail_to = 'mail1@tosendmail.to' . ', ';
$mail_to .= 'mail2@tosendmail.to';
$mail_subject = 'A comment has been made';
$mail_message = '<b> One item has been commented on this page: </b>
<a href="'.$wb->page_link($page['link']).'">'.$wb->page_link($page['link']).'</a>
<b> Title: </b>
'.$title.'
<b> Comment: </b>
'.$comment.'' ;
$wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message);
That was working fine in WB 2.8.2 now I have updated to 2.8.3 it is not working any more.
With 1 email address it is working fine, but with 2 addresses nothing is happening.
So what must be changed to sent a notification mail to 2 email addresses?
Thanks,
Rob
-
Hi,
So what must be changed to sent a notification mail to 2 email addresses?
in wb 283 phpmailer was upgraded to version 5.2 which brings a validation function for email addresses. That's the reason why your solution doesn't work anymore ("email1, email2" is not a valid address).
So you could send mail by mail:
$mail_subject = 'A comment has been made';
$mail_message = '<b> One item has been commented on this page: </b>
<a href="'.$wb->page_link($page['link']).'">'.$wb->page_link($page['link']).'</a>
<b> Title: </b>
'.$title.'
<b> Comment: </b>
'.$comment.'' ;
$wb->mail(SERVER_EMAIL,'mail1@tosendmail.to',$mail_subject,$mail_message);
$wb->mail(SERVER_EMAIL,'mail2@tosendmail.to',$mail_subject,$mail_message);
if you really need to send only one mail with 2 recipients, the only possibility I see is to change the wb core. For example in class.wb.php ~line 418 you find: $myMail->AddAddress($toaddress);
change this to $toaddresses = explode(', ',$toaddress);
foreach($toaddresses as $to)
$myMail->AddAddress($to);
none of these is tested so there is a good chance for errors in it :wink:
regards
-
Thank you for the solution Marmot.
It's correct, with your code WB is now sending two separate emails, but that's no problem for me. :-)
Thanks,
Rob
-
Found this topic and this snippet code works well.
Any idea if a 'moderate' function is possible in the news mod?
-
I noticed that (in my case)
<a href="'.$wb->page_link($page['link']).'">'.$wb->page_link($page['link']).'</a>
is not working properly any more and its output is: www.domain.com/pages.php instead of the specific url on where a comment was placed.
-
Hi Boudi,
the wrong output of the Line <a href="'.$wb->page_link($page['link']).'">'.$wb->page_link($page['link']).'</a> is an effect only.
The reason of is an empty variable $page['link'].
So you must explore, where this VAR has been set and why it's empty.
Manuela
-
correct place for your code lines are after the insert and before the line with the header-location
in the actual SP5 Package (http://forum.WebsiteBaker.org/index.php/topic,28760.msg201484/boardseen.html#new) after line 160 and for line 161
-
Hi folks :)
THnQ for your time and answers. They did the trick! (Y)