Dynamic to - Send an email to a viewed users email address

jjunkie 04 Jan, 2012
Hi there,

I have a joomla 1.5 / CB 1.7.1 based site where an RSVP can be left for a user. For example 'john' would login to his profile, click his friend 'jane' to view her profile and send her an RSVP via a link to chronoform that appears on her CB profile.

Now i have code in the form which when submitted sends an email summary of the RSVP, the email should be going to the recipient of the RSVP not the sender, in this example, Jane should be getting an email with John's RSVP details.

At present however, John is receiving the RSVP summary email as the code in my form takes the user id and finds the email address associated, and it is taking the user id of the 'viewer user' not the 'viewed user'.

Here is the code snippet in my Chronoform:

<?php $val = $_GET['user'];?> 
<?php $user = &JFactory::getUser($val); ?>
<input name="hidden_9" id="hidden_0" type="hidden" value="<?php if ($user->id > 0) echo $user->email ; ?>" />


This is taking the user id of 'John' and getting his email address and then populating the Dynamic To field (hidden_9).

Can anyone please tell me how to get the email address of the person whos profile is being viewed to populate the Dynamic To field instead of the viewers email address?

Many thanks!
GreyHead 04 Jan, 2012
Hi jjunkie ,

I don't know much about CB. Is there anything in the Profile page url that will let you identify Jane and look up her info?

Bob
jjunkie 04 Jan, 2012
Hi Bob!

The url does reveal the userid of the user.

e.g

John's profile:

sitename.com/index.php?option=com_comprofiler&Itemid=2

Jane's profile:

sitename.com/index.php?option=com_comprofiler&task=userProfile&user=146&Itemid=2

146 is Jane's user id.


I also have the following code which works successfully to display the user id of the user whose profile is being viewed (not the id of the viewer)in a section of a profile, however i dont know how/if this could be integrated/replace parts of the existing chronoform code:

<?php global $_CB_framework;
$cbUser = CBuser::getInstance( $_CB_framework->displayedUser() );
$loadtab = $cbUser->getTab('18');	
echo $_CB_framework->displayedUser();
}
?>


Many thanks
jjunkie 06 Jan, 2012
Further to my last post bob, i have thought of another way which should definitely work if you can help with the code.
The rsvp form also requires a user to manually type in the user id of the rsvp recipient.

So could a lookup be carried out on the user id submitted, and use this to populate the dynamic to?

Many thanks
GreyHead 07 Jan, 2012
Hi jjunkie,

Looking at the code in your last post but one you should be able to get the ID you want from the url.
<?php
$v_user = '';
$task = JRequest::getString('task', '', 'get');
if ( $task == 'userProfile' ) {
  $v_user = JRequest::getInt('user', '', 'get');
  $v_user = JFactory::getUser($v_user);
}
?>

That will give you all the info for the viewed used in the $v_user object.

Bob
jjunkie 07 Jan, 2012
Hi Bob!

Many thanks for this, so i understand, this code will get the user id of the user whose profile is being viewed, and place this numeric value in the object $v_user.

But how then can a lookup be performed to get the email address of the user in $v_user?

These are the 2 code snippets now:

<?php $val = $_GET['user'];?> 
<?php $user = &JFactory::getUser($val); ?>
<input name="hidden_9" id="hidden_0" type="hidden" value="<?php if ($user->id > 0) echo $user->email ; ?>" />

<?php
$v_user = '';
$task = JRequest::getString('task', '', 'get');
if ( $task == 'userProfile' ) {
  $v_user = JRequest::getInt('user', '', 'get');
  $v_user = JFactory::getUser($v_user);
}
?>


Do i need to modify something like this? (I would then use hidden_9 as the Dynamic to field for the email):

<input name="hidden_9" id="hidden_0" type="hidden" value="<?php if ($v_user > 0) echo $user->email ; ?>" />


How do i get the email lookup to be performed on v_user value? 😶

Many thanks

P.S i do not need to have the original code now, just the code which finds the viewed user id, and the email address belonging to the viewed user, which is then put into 'hidden_9', which is used in dynamic to.

P.P.S

I tried this, trying to get the logic, it obviously didnt work 😶
<?php
$v_user = '';
$task = JRequest::getString('task', '', 'get');
if ( $task == 'userProfile' ) {
  $v_user =JRequest::getInt('user', '', 'get');
  $user = &JFactory::getUser($v_user);
}
?>
<input name="hidden_9" id="hidden_0" type="hidden" value="<?php if ($user->id > 0) echo $user->email ; ?>" />
GreyHead 08 Jan, 2012
Hi jjunkie ,

The email will be in $v_user->email

Bob
jjunkie 08 Jan, 2012
Hi Bob

how does this look?

 <?php
$v_user = '';
$task = JRequest::getString
('task', '', 'get');
if ( $task == 'userProfile' ) {
$v_user = JRequest::getInt
('user', '', 'get');
$v_user = JFactory::getUser
($v_user);
}
?>
<input name="hidden_9"
id="hidden_0" type="hidden"
value="<?php if ($v_user->id > 0)
echo $v_user->email ; ?>" /> 


 


just like that?

many thanks
GreyHead 08 Jan, 2012
Hi jjunkie,

You have some odd line-breaks in there that might cause problems
<?php
$v_user = '';
$v_user_email = '';
$task = JRequest::getString('task', '', 'get');
if ( $task == 'userProfile' ) {
  $v_user = JRequest::getInt('user', '', 'get');
  $v_user =& JFactory::getUser($v_user);
  $v_user_email =& $v_user->email;
}
?>
<input name="hidden_9" id="hidden_0" type="hidden" value="<?php echo $v_user_email; ?>" />

If the user id is empty
jjunkie 08 Jan, 2012
Hi Bob

Using the code you posted, no email address is retrieved 😟 I have enabled debugging on the form and besides:

Notice You must provide at least one recipient e-mail address.

5. $_POST Array: Array ( [hidden_9] => [vcode] => 135 etc

hidden_9 has no email address / value.
GreyHead 09 Jan, 2012
Hi jjunkie,

The code looks OK to me - I'm afraid that you need to debug it. Echo out the variables step by step to find out where it is breaking.

Bob
This topic is locked and no more replies can be posted.