Forums

Inserting PHP variables in Dynamic To

jet7 17 Feb, 2010
Just getting started with ChronoForms and I'm very impressed with the little I've learned so far. Nice work!

I have two (2) questions:
1. Below is some PHP code I want to use to define the variable $to (in bold below). Where do I place this code in ChronoForms to define the variable?
2. Now that it has be defined, I would like to use it to set the Dynamic To in Setup Emails. What is the syntax I need to use to set the $to varible in the Dynamic To?

Thank you for your help and support.

John

<?php
$db =& JFactory::getDBO();
if ( defined( 'MULTISITES_ID')) {
$site_id = JFilterInput::clean( MULTISITES_ID, 'alnum');
}
else {
$site_id = 'master';
}
$query = "SELECT * FROM #__contact_details WHERE alias='$site_id'";
$db->setQuery($query);
$row = $db->loadObject();
$to = $row->email_to;
?>
GreyHead 17 Feb, 2010
Hi John,

Put the code in the OnSubmit Before box, add this line to store the value in a dummy variable (use a different name if there's any conflict)
JRequest::setVar('to_email', $to);
then put the variable name in the Dynamic To box e.g. to_email (no brackets and no quotes).

Bob
jet7 17 Feb, 2010
Bob,

WOW...thanks for the quick response.

I applied the updates verbatim and received the following message when testing the form.

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

Thanks for the help and support.

John
GreyHead 17 Feb, 2010
Hi John,

Not sure why you are seeing that.
[sendfb][/sendfb]

Bob
jet7 17 Feb, 2010
Bob,

Attached is backup of the form I am testing.

Thanks again for the help and support.

John
GreyHead 17 Feb, 2010
Hi John,

You need the php tags and the rest of the code to define the email
<?php
$db =& JFactory::getDBO();
if ( defined( 'MULTISITES_ID')) {
  $site_id = JFilterInput::clean( MULTISITES_ID, 'alnum');
} else {
  $site_id = 'master';
}
$query = "SELECT * FROM `#__contact_details` WHERE `alias` = '$site_id' ";
$db->setQuery($query);
$row = $db->loadObject();
$to = $row->email_to;
JRequest::setVar('to_email', $to);
?>

Bob
jet7 17 Feb, 2010
Bob,

That did the trick - thanks!

I also want to say that your quality and responsiveness of support on this forum is VERY IMPRESSIVE!

I appreciate the help and support, AND will become a paying customer.

Thanks,

John
jet7 22 Jul, 2010
Bob,

I trust you have been doing well.

Recently I've added Community Builder and had to update the php code you assisted me with to pull the email address from Joomla's users table. To test the code, I used the following code to verify I am pulling the correct email address from Joomla users -
echo "TO = [$to]</br>";


However, when I replace the php code in the above post with the code below email results are not being sent after submitting the form. Attached is a zipped backup of the form.

Thank you for your help and support.

John

<?php
$db =& JFactory::getDBO();
if ( defined( 'MULTISITES_ID')) {
  $site_id = JFilterInput::clean( MULTISITES_ID, 'alnum');
} else {
  $site_id = 'master';
}
$query = 'SELECT c.*, u.email FROM #__comprofiler as c' . ' LEFT JOIN #__users as u ON u.id = c.user_id' . " WHERE cb_alias='$site_id'";
$db->setQuery($query);
$row = $db->loadObject();
$to = $row->email;    
JRequest::setVar('to_email', $to);
?>
jet7 24 Jul, 2010
Bob,

I've continue testing and still nothing.

On the General Tab -

Email the Results? Yes



Setup Email Tab -

Dynamic To: to_email
Subject: Email Subject...
Dynamic Fromname: Name
Dynamic FromEmail: Email



Email Properties -

Email Format: HTML
Record IP: Yes
Enabled: Yes
Use Template Editor: Yes
Enable Attachments: Yes



On Submit Code -
<?php
    $db =& JFactory::getDBO();
    if ( defined( 'MULTISITES_ID')) {
      $site_id = JFilterInput::clean( MULTISITES_ID, 'alnum');
    } else {
      $site_id = 'master';
    }
    $query = 'SELECT c.*, u.email FROM #__comprofiler as c'
           . ' LEFT JOIN #__users as u ON u.id = c.user_id'
           . " WHERE cb_alias='$site_id'"
           ;
    $db->setQuery($query);
    $row = $db->loadObject();
    $to = $row->email;    
    JRequest::setVar('to_email', $to);
    ?>


When I echo "TO = [$to]"; the correct dynamic email is published. After that all I should do is JRequest::setVar('to_email', $to);.

Assistance on this matter would be greatly appreciated - thanks,

John
jet7 24 Jul, 2010
In addition, to determine if there was a conflict, I change to_email to to_email2 on the Setup Email Dynamic To: and the Submit Code - still no emails sent.
GreyHead 26 Jul, 2010
Hi John,

The most likely problem is the Dynamic From Email.

I strongly recommend that you do *not* use the Dynamic From Email element in your Email Setups. Using this often results in your emails being marked as spam and dropped into a spam filter. Instead use the static From Email with an address that matches the site domain name and use Dynamic ReplyTo Email for the user email. The result is the same but with a much better chance of good delivery.

Bob
jet7 27 Jul, 2010
Bob,

Thank you for your quick reply. I will make the changes you suggested - thanks!

In any case I'm still have a problem with the "Dynamic To". This is the real issue I made this post about.

In my test I was using test account emails and checked the spam folders - everything is clean - no emails -spam or inbox.

As you can see above, everything staying the same, emails are not longer being sent after I've modified the php code to dynamically pull email addresses from _users. I can echo the correct email so I know I've got it; however, I can't figure out what causing Chronoforms not to send the email.

Help on this matter is greatly appreciated.

Thanks for all your help and support.

John
jodiewere 27 Jul, 2010
Hi I have emails going to the spam folder. I haven't used dynamic email or anything how to I fix this
GreyHead 27 Jul, 2010
Hi jodiewere,

Impossible to say without seeing an example email (and maybe not then either).

Bob
jet7 27 Jul, 2010
Bob,

It appears jodiewere made a post after my post; therefore, I was never able to get this issue resolved.

In any case I'm still have a problem with the "Dynamic To". This is the real issue I made this post about.

In my test I was using test account emails and checked the spam folders - everything is clean - no emails -spam or inbox.

Old working script pulling email from _contract details
<?php
$db =& JFactory::getDBO();
if ( defined( 'MULTISITES_ID')) {
  $site_id = JFilterInput::clean( MULTISITES_ID, 'alnum');
} else {
  $site_id = 'master';
}
$query = "SELECT * FROM `#__contact_details` WHERE `alias` = '$site_id' ";
$db->setQuery($query);
$row = $db->loadObject();
$to = $row->email_to;
JRequest::setVar('to_email', $to);
?>


Updated script Old pulling email from _users
$db =& JFactory::getDBO();
if ( defined( 'MULTISITES_ID')) {
  $site_id = JFilterInput::clean( MULTISITES_ID, 'alnum');
} else {
  $site_id = 'master';
}
$query = 'SELECT c.*, u.email FROM #__comprofiler as c' . ' LEFT JOIN #__users as u ON u.id = c.user_id' . " WHERE cb_alias='$site_id'";
$db->setQuery($query);
$row = $db->loadObject();
$to = $row->email;   
JRequest::setVar('to_email', $to);
?>


I've verified that I am pulling the correct email address by testing the script with the following echo statement.
echo "TO = [$to]</br>";


As you can see above, everything staying the same, emails are not longer being sent after I've modified the php code to dynamically pull email addresses from _users. I can echo the correct email so I know I've got it; however, I can't figure out what causing Chronoforms not to send the email.

Help on this matter is greatly appreciated.

Thanks for all your help and support.

John
GreyHead 28 Jul, 2010
Hi jet7,

I don't see anything wrong with the code. Please turn DeBug on in the form and post the results here to see if there are any clues in the debug messages or the dummy email.

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