PDA

View Full Version : Email sent to address depending on chosen subject


info231367
08-19-2009, 08:06 AM
Is it possible to have an email sent to a particular email address depending on which subject is chosen? For example, if the "service" subject/option is chosen, the email needs to be sent to the service department's email address. If "sales" is chosen, it needs to be sent to the sales department's email address...and so on. Somebody please tell me how this can be done.

SOJO web
08-19-2009, 11:28 AM
Sure, the quickest way is to wrap the Universal Email into an "if" statement and check if the $_POST variable contains a particular value. You could replicated the wrapped if statement with the email however many more times you needed just changing the variable of the send to address within each and of course modify the value of what your if statement is checking.

So in other words it would like this

if ($_POST['selection'] == "value 1") {

UNIVERSAL EMAIL CODE with address 1

} else if ($_POST['selection'] == "value 2") {

UNIVERSAL EMAIL CODE using address 2

} etc. etc.

So, I would create one Universal Email instance and then just copy like above making a change to the send to address.

Cheers,

Brian

Ray Borduin
08-19-2009, 12:11 PM
That would work, or you could just add the code to the top of the page:
<?php
$defaultAddress = "you@yourcompany.com";
if ($_POST['selection'] == "value 1") {
$defaultAddress = "sales@yourcompany.com";
} else if ($_POST['selection'] == "value 2") {
$defaultAddress = "sales@yourcompany.com";
}
?>
and then specify the email address as <?php echo($defaultAddress); ?> in universal email.

SOJO web
08-19-2009, 12:28 PM
Ray... yeah, I guess that would be more efficient. I was typing too fast without really thinking about logic! :)

info231367
08-21-2009, 05:21 AM
How should it be done if I wanted not only an email sent to a particular email address depending on the subject chosen, but also that same email be sent as a blind courtesy copy to a different email address?

Ray Borduin
08-21-2009, 07:18 AM
Just use the BCC field instead of the to field when you set it to <?php echo($defaultAddress); ?>. You would need to fill out the TO field as well.