News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Simple PM function... could you help?

Started by Dekudude, April 10, 2008, 08:14:25 PM

Previous topic - Next topic

Dekudude

Hi there!

I'm having a slight problem... because I have no idea how to do what I want to do. :'(

Simply put, I'd like to have a simple function like this:

function sendPM ($to, $from, $subject, $message)

Is this possible? It doesn't need to have a BCC, etc, field... I'd just like to have the above parameters, but I don't know how to go about making a function like that. ^_^;; Could anyone write a quick one up for me, or at least give me a quick idea as to how?

Captain_Morrigan


Spaceman-Spiff

If you can tell us what you're trying to do, it may help us answer more accurately.

If you're making a custom script that needs to send PM, you can take a look at function MessagePost() inside Sources/PersonalMessage.php to see how it works.

Dekudude

I simply want a function that sends a personal message via specified parameters... if that makes sense. I'd like it to send $message to $user, from $from. Am I making sense? The function example I showed earlier is an example of what I'd like it to look like... if that's possible.

karlbenson


Dekudude

Hmm, this looks good, except: How do the arrays work? I need a variable to attach the values to, right?

EG:

$to[1]['']

How would I do that?

Spaceman-Spiff

The array part should be optional. It means you can send PMs to multiple or single users IDs.

Example for array:

$to = array(1, 5, 7, 90);

http://ca3.php.net/manual/en/language.types.array.php

Dekudude

Hmmm.....  I tried it out, but it says the function doesn't exist. Which file should I include? I'm including SSI.php right now, but that isn't it. :P

Spaceman-Spiff

include both SSI.php and Sources/Subs-Post.php

Dekudude

Okay, I got THAT working... but now I have another problem:


$submitter = $_GET['submitter'];
$submitter = validText($submitter); // Changes value to HTML Entities to prevent injection.
$submitter = array('', $submitter);

$reason = validText($reason);

$userID = $context['user']['id'];
$userName = $context['user']['name'];
$userUsername = $context['user']['username'];
$reasonSender = array($userID, $userName, $userUsername);



sendpm($submitter,'Your sheet, '.$title.', was not accepted for the following reason...',$reason,false,$reasonSender);


I get all SORTS of errors. What's wrong? O_O

metallica48423

what errors are you getting?  I don't believe you can use that method of string concatenation in pretty much anything but an echo.

try:
sendpm($submitter, "Your sheet, $title, was not accepted for the following reason...", $reason, 0, $reasonSender);
Justin O'Leary
Ex-Project Manager
Ex-Lead Support Specialist

QuoteMicrosoft wants us to "Imagine life without walls"...
I say, "If there are no walls, who needs Windows?"


Useful Links:
Online Manual!
How to Help us Help you
Search
Settings Repair Tool

Dekudude

Quote from: Error
   
Warning: Invalid argument supplied for foreach() in /home/apoldan1/public_html/forum/Sources/Subs-Post.php on line 714

Warning: Invalid argument supplied for foreach() in /home/apoldan1/public_html/forum/Sources/Subs-Post.php on line 714

Warning: array_unique() [function.array-unique]: The argument should be an array in /home/apoldan1/public_html/forum/Sources/Subs-Post.php on line 752

Warning: array_unique() [function.array-unique]: The argument should be an array in /home/apoldan1/public_html/forum/Sources/Subs-Post.php on line 755

Warning: array_diff() [function.array-diff]: Argument #1 is not an array in /home/apoldan1/public_html/forum/Sources/Subs-Post.php on line 755

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/apoldan1/public_html/forum/Sources/Subs-Post.php on line 758

Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/apoldan1/public_html/forum/Sources/Subs-Post.php on line 758

Warning: implode() [function.implode]: Invalid arguments passed in /home/apoldan1/public_html/forum/Sources/Subs-Post.php on line 769

O_O; That's the error I receive. :)

Dekudude

#12
Forgive my double posting, but I have yet another problem, though I fixed the error messages.


<?php

$submitter
= $_GET['submitter'];
$submitter = validText($submitter); //validText() converts string to html_entities, and trims it.
$submitter = array(
'to' => array($submitter),
'bcc' => array()
);
$reason = $_GET['reason'];
$reason = validText($reason);

if (
trim($reason) != "")
{
sendpm($submitter, "Your sheet, $title, was not accepted for the following reason...", $reason);
}


?>


This ALMOST works. The problem, though, is rather awkward: It sends the same PM twice, the second being from no one... forcing the name "guest".

Advertisement: