Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Send PMs (automatically)
Andreas's Avatar
Andreas
Join Date: Jan 2004
Posts: 6,863

 

Germany
Show Printable Version Email this Page Subscription
Andreas Andreas is offline 06-09-2005, 10:00 PM

If you want to (automatically) send a PM to a user, you can use the Class vB_Datamanager_PM.
This class makes sure that all values are correct, handles quota for the recipients, notification eMails, etc.

Example

PHP Code:
// create the DM to do error checking and insert the new PM
$pmdm =& datamanager_init('PM'$vbulletinERRTYPE_ARRAY);
$pmdm->set('fromuserid'1234);
$pmdm->set('fromusername''Welcome-Bot');
$pmdm->set('title''Welcom to our Forums');
$pmdm->set('message'"Hello\nI am a Bot and would like to give you a warm welcome :)");
$pmdm->set_recipients('newuser'$botpermissions);
$pmdm->set('dateline'TIMENOW); 
If anything goes wrong you can check for errors using
PHP Code:
$pmdm->errors 
This is an erray containing the errors.

If everything is OK
PHP Code:
$pmdm->save(); 
This will send a PM to user newuser telling him
Quote:
Hello.
I am a Bot and would like to give you a warm welcome
The message will appear to be coming from User Welcom-Bot (Userid 1234).

$botpermissions must be the permissions for the sending user, but can just be empty.
If you want to send PMs no matter if the PM box of the recipient is full or not:

PHP Code:
$botpermissions['adminpermissions'] = 2
If you want, you can set other options as well ($pmdm->set_info(...)):
  • forward = 1/0 if this is a forwarded PM, Default=0
  • savecopy = 1/0 to keep a copy if the PM in outbox, Default=0
  • receipt = 1/0 to request a read-receipt, Default=0
  • parentpmid = ID of the PM you are responding to (if applicable)

Furthermore you can specify ($pmdm->set(...)):
  • iconid = ID of the message icon the PM should carry, Default=0
  • showsignature = 0/1 Whether the signature should be shown or not, Default=0
  • showsmilie = 0/1 Wheter smilies should be parsed or not, Default=1

For multiple receipients just use user1;user2;useer3.

This How-To is (C) 2005 by KirbyDE and you are not allowed to redistribute it in any way without my explicit consent.
Reply With Quote
  #52  
Old 12-14-2006, 06:43 PM
mferguson's Avatar
mferguson mferguson is offline
 
Join Date: Jan 2003
Location: Colorado
Posts: 274
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Are you wanting to bulk email members based on a cron? If so the only thing I believe you need to do would be to figure out what you needed to populate when the cron is run (ie - subject, body, etc.)

Mark
Reply With Quote
  #53  
Old 12-14-2006, 06:54 PM
Blaine0002's Avatar
Blaine0002 Blaine0002 is offline
 
Join Date: Jul 2003
Location: Wisconsin.
Posts: 1,350
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

no, only want it to send 2 pms, but its not sending any, and the cron IS being run correctly.
Reply With Quote
  #54  
Old 12-14-2006, 07:16 PM
mferguson's Avatar
mferguson mferguson is offline
 
Join Date: Jan 2003
Location: Colorado
Posts: 274
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I guess I'm confused as to why you are doing this with a cron. If you can provide some background it will give me a better idea of how it might be done.

As to the cron itself. How are you verifying that it is being run correctly? Is there some type of output being generated?

Thanks

Mark
Reply With Quote
  #55  
Old 12-15-2006, 12:05 AM
Blaine0002's Avatar
Blaine0002 Blaine0002 is offline
 
Join Date: Jul 2003
Location: Wisconsin.
Posts: 1,350
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

in my auction modification, a cron runs every 10 minutes which closes auctions and notifies buyer and seller of who won.
Reply With Quote
  #56  
Old 12-20-2006, 05:27 PM
paul41598's Avatar
paul41598 paul41598 is offline
 
Join Date: Jun 2004
Location: MI
Posts: 732
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Um I have the below code in a cron job, and when it runs Im getting this error:

PHP Code:
Fatal errorUnable to proceed with save while $errors array is not empty in class vb_datamanager_pm in /includes/class_dm.php on line 758 

Code:
      // Fetch the PM message  
	if ($vbulletin->options['ptp_pm_on_off'] == '1') 
	{
		     $ptp_pm =
          construct_phrase(
            $vbphrase['ptp_alertpm'],
            $pquery['username'],
          );
      
      // Send a PM to user(s)
      $pmdm =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY);
      $pmdm->set('fromuserid', 6);
      $pmdm->set('fromusername', 'JonB');
      $pmdm->set('title', 'Crap');
      $pmdm->overridequota = true; 
      $pmdm->set('message', 'test');
      $pmdm->set_recipients($pquery['username'], $botpermissions);
      $pmdm->set('dateline', TIMENOW);
      $pmdm->save();
	}
Whats wrong here? I think it worked before now all of a sudden doesnt... (I think) :cross-eyed:
Reply With Quote
  #57  
Old 12-20-2006, 09:06 PM
jwocky jwocky is offline
 
Join Date: Mar 2005
Posts: 138
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by paul41598 View Post
Um I have the below code in a cron job, and when it runs Im getting this error:

PHP Code:
Fatal errorUnable to proceed with save while $errors array is not empty in class vb_datamanager_pm in /includes/class_dm.php on line 758 

Code:
      // Fetch the PM message  
	if ($vbulletin->options['ptp_pm_on_off'] == '1') 
	{
		     $ptp_pm =
          construct_phrase(
            $vbphrase['ptp_alertpm'],
            $pquery['username'],
          );
      
      // Send a PM to user(s)
      $pmdm =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY);
      $pmdm->set('fromuserid', 6);
      $pmdm->set('fromusername', 'JonB');
      $pmdm->set('title', 'Crap');
      $pmdm->overridequota = true; 
      $pmdm->set('message', 'test');
      $pmdm->set_recipients($pquery['username'], $botpermissions);
      $pmdm->set('dateline', TIMENOW);
      $pmdm->save();
	}
Whats wrong here? I think it worked before now all of a sudden doesnt... (I think) :cross-eyed:
Wow, i'm having the identical error message which just started today as well, I wonder whats going on here... and I mean identical Is there a way to get the script to echo the error? return $pmdm->errors; ? I have that in my cron script, but when i run it in the task manager i get no text echoed, maybee another way so that we can diagnose this problem
Reply With Quote
  #58  
Old 12-20-2006, 09:41 PM
Blaine0002's Avatar
Blaine0002 Blaine0002 is offline
 
Join Date: Jul 2003
Location: Wisconsin.
Posts: 1,350
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
echo $pmdm->errors
When i did a cron i actually made a seperate function and ran the function from the cron.
Reply With Quote
  #59  
Old 12-20-2006, 09:44 PM
jwocky jwocky is offline
 
Join Date: Mar 2005
Posts: 138
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Blaine0002 View Post
PHP Code:
echo $pmdm->errors
When i did a cron i actually made a seperate function and ran the function from the cron.
That just prints out the word "Array" .. dont know how to parse that pmdm->errors to give us some valuable data on diagnosing the problem
Reply With Quote
  #60  
Old 12-20-2006, 10:27 PM
paul41598's Avatar
paul41598 paul41598 is offline
 
Join Date: Jun 2004
Location: MI
Posts: 732
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

actually if I take out the PM datamanager code temporarily...and replace with this:

Code:
      $pmto_users[] = $pquery['username'];

      $pmtousernames = implode(';', $pmto_users); 
 			echo "$pmtousernames";
I get CMUrickCMUrick;Pepsico

Its printing out CMUrick twice and I have no idea why. But its working kinda...

jwocky: You need the code in this post I think to grab names and put em in an array, then you will get a different output in your tests.
Reply With Quote
  #61  
Old 12-20-2006, 11:43 PM
jwocky jwocky is offline
 
Join Date: Mar 2005
Posts: 138
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by paul41598 View Post
actually if I take out the PM datamanager code temporarily...and replace with this:

Code:
      $pmto_users[] = $pquery['username'];

      $pmtousernames = implode(';', $pmto_users); 
 			echo "$pmtousernames";
I get CMUrickCMUrick;Pepsico

Its printing out CMUrick twice and I have no idea why. But its working kinda...

jwocky: You need the code in this post I think to grab names and put em in an array, then you will get a different output in your tests.

Ok, i imploded the array $pmdm->errors in the same way you did above and got it to spit out the error code, turns out in my case, the user set to recieve the PM had his inbox full! argh.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:02 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07388 seconds
  • Memory Usage 2,331KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (4)bbcode_code
  • (8)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (3)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete