Forums

Send e-Mail based to a selection

giorgos147 14 Aug, 2010
Hi!
I am George!

I have a radio site, and I want my visitors to send me their dedication. I want to have a form, where the visitors can choose the producer, and I want the e-Mail to be send at the producers e-mail.

I've searched the FAQs, and I've used the FAQ #31. Also, I've searched the forum, but I couldn't find any answer for me.

The code I've used is:

To my HTML Form:
<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Παραγωγός(Producer)</label>
    <select class="cf_inputbox validate-selection" id="recipients" size="1" title="Αυτό το πεδίο είναι υποχρεωτικό."  name="recipients">
  <option value="em1">Name 1</option>
  <option value="em2">Name 2</option>
  <option value="em3">Name 3</option>
    </select>


and the On Submit code - before sending email is:
<?php
$emails_2 = array('em1'=>'sample1@email.com', 'em2'=>'sample2@email.com', 'em3'=>'name_3@example.com', . . .);
$MyForm =& CFChronoForm::getInstance('form_name_here');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'to', $emails_2[$_POST['recipients']]);
?> 


What I am doing wrong?
I can't send any e-mail from the form.

Thanks in advance!

George,
Greece


Sorry for my English.
GreyHead 14 Aug, 2010
Hi George,

Please check the Emails Tutorial from the Tutorials link above to see how to set up emails to use this code.

Bob
giorgos147 14 Aug, 2010
I read the "Adding emails to a form in ChronoForms", but I still can't understand how to use it 😟
GreyHead 14 Aug, 2010
Hi George,

It's pretty simple. I suggest that you follow the tutorial, get it sending emails OK, then add the code from your previous post.

Bob
giorgos147 14 Aug, 2010
Thanks Bob!

I don't have the time to test it now, but I can't understand how the PHP takes the selected name from the e-mail Setup.

For example, we have to producers, Bob, and me, George. The visitor chose you(Bob). Then, how the "code" selects only your e-mail, and don't send the e-mail to me too? I don't give any Value to the e-mail setup of the form. (For example, yours is
<option value="Bob">Bob</option>
and in the On submit code is:
$emails_2 = array('Bob'=>'Bob@email.com', 'em2'=>'sample2@email.com', 'em3'=>'name_3@example.com', . . .);
)

Anyway! I'll give it a try later in the night!
Thanks very much!
GreyHead 14 Aug, 2010
Hi George,

This line
$MyFormEmails->setEmailData(1, 'to', $emails_2[$_POST['recipients']]);
sets the To Email value directly.

Bob
giorgos147 14 Aug, 2010
I feel so stupid...

I can't get it to work!

In "Setup Emails" I have: A "To" form where I have my basic emails where I want to send my email by default, and as a copy.
Down of this, I have a "Dynamic To" form, where I have for example, your e-mail, and mine.(Producers email)

Then, in the HTML form I have:
<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Παραγωγός:</label>
    <select class="cf_inputbox validate-selection" id="recipients" size="1" title="Αυτό το πεδίο είναι υποχρεωτικό."  name="recipients">
    <option value="">Κάντε μία επιλογή:</option>
      <option value="em1">Bob</option>
<option value="em2">George</option>

    </select>


and in the "On submit code" I have:
<?php
$emails_2 = array('em1'=>'bob@email.com', 'em2'=>'george@email.com', 'em3'=>'name_3@example.com', . . .);
$MyForm =& CFChronoForm::getInstance('askform');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'to', $emails_2[$_POST['recipients']]);
?> 


The "askform" in here
$MyForm =& CFChronoForm::getInstance('askform');
is the name of my form.

What am I doing wrong? 😟
GreyHead 15 Aug, 2010
Hi George,

Have you followed the Tutorial and got a simple Email to work?

Bob
giorgos147 15 Aug, 2010
Hi Bob!

Yes, of course! I have too many forms, and I know how chronoforms work. I just only can't make it work in the way I want.
GreyHead 15 Aug, 2010
Hi George,

I know how chronoforms work.

Sorry, I have no way of knowing that from here.

The code from the FAQ is designed to replace the values in a To element, not to work with a Dynamic To.

Change the code in the OnSubmit Before Box to something like this:
<?php
$emails_2 = array('em1'=>'bob@email.com', 'em2'=>'george@email.com', 'em3'=>'name_3@example.com');
$dyn_to = JRequest::GetString('recipients', '', 'post');
if ( $dyn_to ) {
  $dyn_to = $emails_2[$dyn_to];
}
JRequest::setVar('dyn_to', $dyn_to);
?>
Then put dyn_to into the Dynamic To box.

Bob
giorgos147 15 Aug, 2010
Thank you, thank you, thank you Bob! 😀

When I said "I know how chronoforms work." I meant that I know how they work at "the simple way".

Anyway! 🙂

Another question: I have this: http://extensions.joomla.org/extensions/multimedia/shoutcast-a-podcasts/8516?qh=YToxOntpOjA7czo5OiJzaG91dGNhc3QiO30%3D, and I want when a producer is live, in the form that we created, to show at his name for example: Bob - Live Now!

If you don't understand me: I have the form, and the drop-down menu where I have the producers. I want near the producer that is live(and he/she is streaming), to have as I said: Bob - Live.

Is there any way to do this? And, can I have the form open only when a producer is live? I know that I can do this with watchman, but I want it to work only when someone is streaming.

Thanks Bob, and sorry for my English! 🙂
GreyHead 15 Aug, 2010
Hi George,

How do you know if someone is 'live'?

Bob
giorgos147 15 Aug, 2010
Ooops! I didn't realise that I can't know who is online 😛 I just thought that I can "connect" it with shoutcast, but I didn't think of how I can know when for example, you, Bob, are online, as we all have dynamic IPs. (sorry if you can't understand me... 😑 )
Anyway! No problem!

Thanks again Bob! 😀
GreyHead 16 Aug, 2010
Hi George,

I'm sure that there is a way of doing it - this forum sets a little 'online' flag when users are on-line. But in coding terms I don’t know what to check to discover this.

Bob
willp 31 Aug, 2010
I too am trying to setup multiple recipients that the user selects from but with no success.
I was using the dynamic to field as well but couldn't get it to work with the above modifications so i changed it to the basic to field and copied the code as described int he FAQ but with no success. It doesn't seem to override the default to value that i put as it doesn't matter which one i select fromt he drop down, it always sends it through to the default email address, any ideas?, thanks.
GreyHead 31 Aug, 2010
Hi willp,

The code in the FAQ will only work with a Dynamic To element. If you want to send a copy to an Admin as well then you can add a To element as well as the Dynamic To.

Bob
willp 01 Sep, 2010
Sorry, I'm a bit confused. On page 1 of the thread you mentioned "The code from the FAQ is designed to replace the values in a To element, not to work with a Dynamic To." but now is it the other way around?

Which to should i use withthe FAQ?, and i'll try it again, thanks.
GreyHead 01 Sep, 2010
Hi willp,

My apologies I wrote without checking the FAQ.

For the ChronoForms Book I re-wrote the code like this
<?php
$radio0 = JRequest::getString('radio0', 'admin', 'post');
$emails = array (
'em1' => 'accounts@example.com',
'em2' => 'technical@example.com',
'em3' => 'sales@example.com',
'em4' => 'admin@example.com'
);
$email_to_use = $emails[$radio0];
JRequest::setVar('email_to_use', $email_to_use);
?>
This version 'will' only work with the Dynamic To box; put email_to_use in the Dynamic To box.

Bob
willp 01 Sep, 2010
Hi, I have tried that without any success.

I added this code to the form html:
Select the recipient you wish to contact:
<select name="recipients">
  <option value="em1">Peterhead</option>
  <option value="em2">Kinlochbervie</option>
  <option value="em3">Macduff</option>
</select>


Then the following to the on submit before sending:
<?php
$radio0 = JRequest::getString('radio0', 'admin', 'post');
$emails = array (
'em1' => 'willp@testemail1.co.uk',
'em2' => 'willp@testemail2.co.uk',
'em3' => 'willp@testemail3.co.uk',
);
$email_to_use = $emails[$radio0];
JRequest::setVar('email_to_use', $email_to_use);
?>

The form is using the dynamic to and i added "email_to_use" in the dynamic to box.

When i submit a form i just get an error stating "! You must provide at least one recipient e-mail address." any ideas as to where i'm going wrong?, thanks for the help
GreyHead 01 Sep, 2010
Hi willp,

The input names need to match up - you have 'recipients' in the Form HTML and 'radio0' in the OnSubmit code. Here's the OnSubmit code using 'recipients'
<?php
$recipient = JRequest::getString('recipients', '', 'post');
$emails = array (
'em1' => 'willp@testemail1.co.uk',
'em2' => 'willp@testemail2.co.uk',
'em3' => 'willp@testemail3.co.uk',
);
$email_to_use = $emails[$recipient];
JRequest::setVar('email_to_use', $email_to_use);
?>
I've removed the default value 'admin' from the JRequest line. If you want to set a default value then put one of the em1, em2, em3 in there e.g.
$recipient = JRequest::getString('recipients', 'em1', 'post');


Bob
willp 01 Sep, 2010
Excellent!, i was going to ask what radio0 was for. It works a charm now, thanks so much for your help, its really appreciated.
This topic is locked and no more replies can be posted.