Forums

[solved] Send mail with condition

schlogo 20 Jul, 2011
Hello

here s what i want to do. I ve have two emails setup in a chronoforms 3.2 form. Before sending,I need to check a value from the form, if this value starts with 10,11 and 12, email must be sent with email 1 setup, if value is something else, it has to be sent with email 2 setup

Can this be done easily ? I can t find how !

tks for your help !
GreyHead 21 Jul, 2011
Hi schlogo,

Please see Max's post here for the method to use with CFv3.2

Bob
schlogo 21 Jul, 2011
hello
tks for your link, looks great , i ve adapted the solution but it does not work, can you see where i am wrong?

tks !

$MyForm =& CFChronoForm::getInstance('diaglecontenu');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$codepostal = $_POST['text_5'];
$zipfirst2 = substr($codepostal,0,2);
if($zipfirst2  == "95" || $zipfirst2  == "78" || $zipfirst2  == "91" || $zipfirst2  == "77" || $zipfirst2  == "94" || $zipfirst2  == "75" || $zipfirst2  == "92" || $zipfirst2  == "93") {
$MyFormEmails->setEmailData(1, 'enabled', '1');//enable  email 1
$MyFormEmails->setEmailData(2, 'enabled', '1');//enable  email 2
$MyFormEmails->setEmailData(3, 'enabled', '0');//disable email 3
}else{
$MyFormEmails->setEmailData(1, 'enabled', '0');//disable email 1
$MyFormEmails->setEmailData(2, 'enabled', '1');//disable email 2
$MyFormEmails->setEmailData(3, 'enabled', '1');//enable email 3
}
GreyHead 21 Jul, 2011
Hi schlogo,

The code looks OK from a quick scan. How does it fail? That might give a clue. What do you see with Debug on?

Presumably this code is in the OnSubmit Before Email box?

I recall that previously we've had to set all the emails to 'disabled' in their Properties box - I'm not sure if that is needed here.

Bob
schlogo 21 Jul, 2011
Hello

Sorry for the lack of information, it sends all the emails at every shot,i am going to disable the emails to see if it changes something. Maybe the substr is not working , i m digging
schlogo 22 Jul, 2011
Hello

The solution is....Sleep is good for the brain ! I simply forgot to add the php brackets on the above code ... Added them today at 7:00AM made it work perfectly at 7:01AM !

Tks for your help !

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