Different notification email recipients based on chosen subject

You might want to change the recipients of the email based on the subject chosen by the form user. To do this you will need to change the recipients array depending on which subject was chosen. The code below shows an example of how you would do this and this code will replace the existing code that sets the notification recipients in process.php. The string after case should match the value attribute of the option in the select menu HTML of the form.

Different recipients per subject

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
switch($_POST['subject']) {
    case 'General enquiry':
        $config['recipients'] = array(
            'email1@example.com',
            'email2@example.com',
            'email3@example.com'
        );
        break;
    case 'Sales enquiry':
        $config['recipients'] = array(
            'email4@example.com',
            'email5@example.com',
            'email6@example.com'
        );
        break;
    case 'Support enquiry':
        $config['recipients'] = array(
            'email7@example.com',
            'email8@example.com',
            'email9@example.com'
        );
        break;
    default:
        // These will be the recipients if the subject does not match any above
        $config['recipients'] = array(
            'email1@example.com',
            'email4@example.com',
            'email7@example.com'
        );
        break;
}
switch($_POST['subject']) {
    case 'General enquiry':
        $config['recipients'] = array(
            'email1@example.com',
            'email2@example.com',
            'email3@example.com'
        );
        break;
    case 'Sales enquiry':
        $config['recipients'] = array(
            'email4@example.com',
            'email5@example.com',
            'email6@example.com'
        );
        break;
    case 'Support enquiry':
        $config['recipients'] = array(
            'email7@example.com',
            'email8@example.com',
            'email9@example.com'
        );
        break;
    default:
        // These will be the recipients if the subject does not match any above
        $config['recipients'] = array(
            'email1@example.com',
            'email4@example.com',
            'email7@example.com'
        );
        break;
}

Still having trouble? Head over to the forums.

Forums