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
  #92  
Old 07-18-2008, 01:51 PM
Rich's Avatar
Rich Rich is offline
 
Join Date: Mar 2004
Location: U.S.A
Posts: 921
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Jase2 View Post
Hi Andreas,

The following bit:

PHP Code:
$pmdm->set('message'"Hello\nI am a Bot and would like to give you a warm welcome :)"); 
How would I go about changing this to a phrase, so that users can have the message however they like. Is it possible?

Thanks.

-- Jason
Thats actually pretty easy Jason. You need to set 2 things.

First you need this BEFORE the message is called to be sent:

$message = $vbphrase[your_phrase];

Then change the line you have posted above to read:

$pmdm->set('message', $message);
Reply With Quote
  #93  
Old 09-03-2008, 08:40 PM
squishi squishi is offline
 
Join Date: May 2006
Location: Frankfurt
Posts: 282
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Does this work with 3.7.3?
And if so, wkhat file do I need to include in the php file?
Reply With Quote
  #94  
Old 09-09-2008, 02:03 PM
veenuisthebest's Avatar
veenuisthebest veenuisthebest is offline
 
Join Date: Mar 2008
Location: India
Posts: 1,416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by squishi View Post
Does this work with 3.7.3?
And if so, wkhat file do I need to include in the php file?
yes it would work in all versions of vb

no file to include.
Reply With Quote
  #95  
Old 04-07-2009, 04:53 AM
Excalibur82 Excalibur82 is offline
 
Join Date: Dec 2008
Posts: 175
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Since my code deals with PM's I need to exclude myself from receiving a PM as I am the one making the new comment.

PHP Code:
            $useri $db->query_read("
                SELECT * FROM " 
TABLE_PREFIX "threadcomment
                WHERE threadid = 
$threadinfo[threadid]
            "
); 
Now what I am trying to do is this (I know this won't work but an example of what I need:
PHP Code:
            $useri $db->query_read("
                SELECT * FROM " 
TABLE_PREFIX "threadcomment
                WHERE threadid = 
$threadinfo[threadid]
                IGNORE userid = 
$vbulletin->userinfo['userid']
            "
); 
I couldn't find anything to exclude my id, does anyone know how to do this?

Thanks
Reply With Quote
  #96  
Old 04-07-2009, 03:58 PM
mferguson's Avatar
mferguson mferguson is offline
 
Join Date: Jan 2003
Location: Colorado
Posts: 274
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You should be able to exclude yourself using the following query given that userid is a column in the threadcomment table.

PHP Code:
$useri $db->query_read("
       SELECT * FROM " 
TABLE_PREFIX "threadcomment
                WHERE threadid = 
$threadinfo[threadid]
                AND userid != 
$vbulletin->userinfo['userid']
"
); 
Reply With Quote
  #97  
Old 04-07-2009, 05:52 PM
Excalibur82 Excalibur82 is offline
 
Join Date: Dec 2008
Posts: 175
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you very much, thats what I needed.

Had to change it:
PHP Code:
$useri $db->query_read("
       SELECT * FROM " 
TABLE_PREFIX "threadcomment
                WHERE threadid = 
$threadinfo[threadid]
                AND userid != " 
$vbulletin->userinfo['userid'] . "
"
); 
Works like a charm.
Reply With Quote
  #98  
Old 04-07-2009, 08:22 PM
mferguson's Avatar
mferguson mferguson is offline
 
Join Date: Jan 2003
Location: Colorado
Posts: 274
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Glad to help!
Reply With Quote
  #99  
Old 05-02-2010, 11:58 PM
bpr bpr is offline
 
Join Date: Dec 2009
Location: London
Posts: 57
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is it possible to transfer it for the vb 4.0. x ?
Reply With Quote
  #100  
Old 05-13-2010, 07:22 PM
steveheinsch steveheinsch is offline
 
Join Date: Mar 2007
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am sending to a lot of recipients at once. Its in a loop sending to 20 recipients at a time (user1;user2;etc)

Occasionally Ill get the following error when checking $pmdm->errors:

Quote:
XXXX has chosen not to receive private messages or may not be allowed to receive private messages. Therefore you may not send your message to him/her.

If you are trying to send this message to multiple recipients, remove XXXX from the recipient list and send the message again.
How does one check to see if someone is allowed to receive a PM before its sent so I can exclude them from the recipients?

I am using $botpermissions['adminpermissions'] = 2; to override if their mailbox is full, but don't want to send a PM to people who aren't allowed by way of permissions to receive them.

Can this be checked in the query I am using to select names from the user table? Or is there code that can be used to check to see if the user is able to receive PM's?

I appreciate any insight.
Thanks,
Steve
Reply With Quote
  #101  
Old 12-13-2012, 01:51 AM
Easy5s.net Easy5s.net is offline
 
Join Date: Jun 2011
Posts: 201
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hello, I want send a content to two people, but different title, how to?
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 08:08 AM.


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.04985 seconds
  • Memory Usage 2,329KB
  • Queries Executed 27 (?)
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
  • (9)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
  • (2)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_postinfo_query
  • fetch_postinfo
  • 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