Send PMs from outside of phpBB

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
JustChise
Registered User
Posts: 95
Joined: Thu Oct 30, 2014 4:56 am

Send PMs from outside of phpBB

Post by JustChise »

Hello. I have a site where we run games and post registration topics in the forum. What I would like to be able to do, tho, is send PMs to all users that have participated in the past using a php script that exists separately from the phpBB software itself. So I'm just wondering if someone can point me towards the bare minimum I need to extract or replicate from the functions_privmsgs.php? Basically I want to automate the sending of these PMs to specific users and make sure they both get an email as well as a notification with the idea that if they haven't visited the forum recently, they'd at least see the email notification for the PM. Thanks.

Support Request Template
What version of phpBB are you using? phpBB 3.2.2
What is your board's URL? http://www.stablewars.com/forum
Who do you host your board with? Go Daddy
How did you install your board? I used the automatic download package from phpBB.com
What is the most recent action performed on your board? Update from a previous version of phpBB3.2
Is registration required to reproduce this issue? N/A
Do you have any MODs installed? No
What version of phpBB3 did you update from? N/A
What styles do you currently have installed? prosilver and a few others
What language(s) is your board currently using? English
Which database type/version are you using? MySQL 5
What is your level of experience? Not new to phpBB nor PHP
What username can be used to view this issue? No answer given
What password can be used to view this issue? No answer given
When did your problem begin? Not really a problem but a general question.
Please describe your problem. See description of question above...
Generated by SRT Generator
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 3732
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay
Contact:

Re: Send PMs from outside of phpBB

Post by Kailey »

From includes\ucp\ucp_pm_compose.php. Obviously this will need to be adjusted accordingly. You would need to include the functions_privmsgs.php file.

Code: Select all

			$pm_data = array(
				'msg_id'				=> (int) $msg_id,
				'from_user_id'			=> $user->data['user_id'],
				'from_user_ip'			=> $user->ip,
				'from_username'			=> $user->data['username'],
				'reply_from_root_level'	=> (isset($post['root_level'])) ? (int) $post['root_level'] : 0,
				'reply_from_msg_id'		=> (int) $msg_id,
				'icon_id'				=> (int) $icon_id,
				'enable_sig'			=> (bool) $enable_sig,
				'enable_bbcode'			=> (bool) $enable_bbcode,
				'enable_smilies'		=> (bool) $enable_smilies,
				'enable_urls'			=> (bool) $enable_urls,
				'bbcode_bitfield'		=> $message_parser->bbcode_bitfield,
				'bbcode_uid'			=> $message_parser->bbcode_uid,
				'message'				=> $message_parser->message,
				'attachment_data'		=> $message_parser->attachment_data,
				'filename_data'			=> $message_parser->filename_data,
				'address_list'			=> $address_list
			);

			$msg_id = submit_pm($action, $subject, $pm_data);
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules

If you have any questions about the rules/customs of this website, feel free to send me a PM.
JustChise
Registered User
Posts: 95
Joined: Thu Oct 30, 2014 4:56 am

Re: Send PMs from outside of phpBB

Post by JustChise »

Thanks kinerity. I will give it a shot tomorrow but it looks pretty straight forward.
JustChise
Registered User
Posts: 95
Joined: Thu Oct 30, 2014 4:56 am

Re: Send PMs from outside of phpBB

Post by JustChise »

Okay so I finally had a pressing need to use this and got this working today but when I submit the PM, the users are not getting notifications of a new PM being available. They get the new message number by the PM link while logged in but no local notifications or emails of new PMs are being generated even though they get emails for regular PMs. Everything seems to work as expected except the notification piece. My code is below; is there some step I'm missing to trigger the notifications?

Code: Select all

			define("IN_PHPBB", true);
			$phpbb_root_path = (defined("PHPBB_ROOT_PATH")) ? PHPBB_ROOT_PATH : "../forum/";
			$phpEx = substr(strrchr(__FILE__, "."), 1);
			include($phpbb_root_path . "common." . $phpEx);
			include($phpbb_root_path . "includes/functions_display." . $phpEx);
			include($phpbb_root_path . "includes/message_parser." . $phpEx);
			include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);

			// Start session management
			$user_id = 14810;
			$user->session_create($user_id);
			$auth->acl($user->data);

			//Variables to hold the parameters for submit_pm.
			$poll = $uid = $bitfield = $options = ''; 
			generate_text_for_storage($message, $uid, $bitfield, $options, true, true, true);

			$addressList = array();
			//sql to get users (database query removed for security)
			while (...) {
				$addressList[$row4['user_id']] = 'bcc';
			}

			$data = array( 
			    'address_list'      => array('u' => $addressList),
			    'from_user_id'      => $user_id,
			    'from_username'     => 'Test',
			    'icon_id'           => 0,
			    'from_user_ip'      => $user->ip,
			     
			    'enable_bbcode'     => true,
			    'enable_smilies'    => true,
			    'enable_urls'       => true,
			    'enable_sig'        => true,
			
			    'message'           => $message,
			    'bbcode_bitfield'   => $bitfield,
			    'bbcode_uid'        => $uid,
			);
			
			submit_pm('post', $subject, $data, false);

			// End session management
			$user->session_kill(false);
Support Request Template
What version of phpBB are you using? phpBB 3.2.5
What is your board's URL? http://www.stablewars.com/forum
Who do you host your board with? Go Daddy
How did you install your board? I used the automatic download package from phpBB.com
What is the most recent action performed on your board? Update from a previous version of phpBB3.2
Is registration required to reproduce this issue? N/A
Do you have any MODs installed? No
What version of phpBB3 did you update from? N/A
What styles do you currently have installed? prosilver and a few others
What language(s) is your board currently using? English
Which database type/version are you using? MySQL 5
What is your level of experience? Not new to phpBB nor PHP
What username can be used to view this issue? No answer given
What password can be used to view this issue? No answer given
When did your problem begin? When I added the submit_pm logic to an external program.
Please describe your problem. See description of question above...
Generated by SRT Generator
JustChise
Registered User
Posts: 95
Joined: Thu Oct 30, 2014 4:56 am

Re: Send PMs from outside of phpBB

Post by JustChise »

This can be marked as answered/closed now since the above code works fine as I realized my test was sending the PM from the same account to itself so no notification was generated for that. Guess that's what I get for trying to do this at 2am...
Post Reply

Return to “phpBB Custom Coding”