Forums

Send email to different people depending on select

tgryffyn 10 Jun, 2008
First, thanks for ChronoForms, it's an amazing addon for Joomla that's doing almost exactly what our client needs. "Almost" is the key word, and that's really just because I'm doing something wrong.

Currently, I have the form send a respond to the user filling out the form, but I also need to send an email to my client but it depends on the type of problem being reported. Basically I need to send a notification email to a different department head depending on a <select> body on the form.

So the form has a "category" select box and I created some PHP code to put in Form Code -> On Submit code after sending email. (doesn't matter if it's before or after really).

I use a switch() statement to set the $subject and $contact_email depending on the category selected, then I tried using this code stolen from another Joomla component:

$mailer =& JFactory::getMailer();
$mailer->setSender($from);
$mailer->setSubject($subject);
$mailer->setBody($body);
$mailer->IsHTML(false);
$mailer->addRecipient($contact_email);
$rs = $mailer->Send();


I also tried using what ChronoForms uses:

$email_sent = JUtility::sendMail($from, $fromname, $recipient, $subject, $html_message, true, $ccemails, $bccemails, $attachments, $replyto_email, $replyto_name );

(changing the appropriate variables)


Anyway, maybe I'm doing this the hard way, but I'm doing something wrong here.

Any thoughts, anyone?

I searched the forums, but didn't see an appropriate answer. But my brain's fried and I may just not have been looking in the right place.

Thanks in advance!

-TG
tgryffyn 10 Jun, 2008
Ok.. I was premature. Looks like the ChronoForm code worked. Typically mail sent to my $recipient email address goes through nearly immediately. It must have been cached on the sending server or something. Just got three test messages in a row.

So if anyone else is trying to do this, use this to send email from PHP before/after code:
$email_sent = JUtility::sendMail($from, 
$fromname, $recipient, $subject, $html_message, true, 
$ccemails, $bccemails, $attachments, $replyto_email, 
$replyto_name );


btw.. that's "sendmail($from.." I don't see an option to turn off emoticon conversion.
GreyHead 10 Jun, 2008
Hi tgryffyn,

Great, glad it's working for you.

Bob

PS use 'code' tags to hide the smileys.
tgryffyn 10 Jun, 2008
Ah thanks.. was in too much of a hurry and didn't see the 'code' tag.

Anyway, thought someone else might benefit from this tip about sending alternate emails (or maybe there was a feature in Chrono that I hadn't noticed).

Thanks again for everything!
jcksnps4 18 Jun, 2008
I'm having a problem with this. I'm currently using this code in my "On Submit - Before email" box:


<?php 
//create dynamic subject
$rows[0]->emailsubject =  
  "KB Submissions - ".$_POST['reqtype']." by ".$_POST['username'];  

//clerical change? email the clerk.
$reqtype = $_POST['reqtype'];
if ($reqtype == "Clerical") {
   $recipient = "clerical@domain.com";
}
?>


I tried using the post values directly, but that didn't work...

I'm only wanting to change the TO email address. Is all the other code necessary that's posted here?
GreyHead 18 Jun, 2008
Hi jcksnps4,

I'm not clear quite what the problem is but this code should be enough:
<?php
//clerical change? email the clerk. 
$reqtype = $_POST['reqtype']; 
if ($reqtype == "Clerical") { 
  $recipient = "clerical@domain.com"; 
} 
?>
Bob
jcksnps4 18 Jun, 2008
I think I got it:


<?php //clerical change? email the clerk. 
$reqtype = $_POST['reqtype']; 
if ($reqtype == "Clerical") { 
   $rows[0]->extraemail = "clerical@domain.com"; } 
?>



Seems to be working...lol I just don't have access to the other email and my co-worker went to lunch. :laugh:
knaap 25 Jun, 2008
I have the same question but the shown solution doesn't work for me.

My client uses an autoresponse system in different languages.

The webform uses country selection in dropdown.

Everything works fine but my clients now wants the form sent to a different email adres when the country selected is "Spain".

I tried the follwing code but that doesn't work

<?php $country = $_POST['country']; if ($country == "Spain") { $recipient = "spain@domain.com"; } ?>


What am I missing?

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