Selectable Recipient with Pipes

Imagine that you are a webmaster of a company and you need a contact form on your site which will allow the sender to select an email recipient. Let’s say that the options are the CEO of the company (ceo@example.com), the sales department (sales@example.com) and the support department (support@example.com).

You’ve been able to achieve this with Contact Form 7 in this way: first, make a drop-down menu or radio button for the selection (you can do this by inserting a form tag such as:

[select your-recipient "ceo@example.com"
                    "sales@example.com"
                    "support@example.com"]

into the form template); second, enter a corresponding mail tag [your-recipient] into the To: field in the Mail section. This ensures that the email is sent to the specific address that the sender selected.

However, there has been a problem with this. By using this procedure, the email addresses are revealed over the Internet and this is not good. These addresses could then become targets of evil spammers very quickly.

So, what you need is a way to allow senders to select from closed data safely. The pipe (‘|’) support is just for this very purpose.

Change the form tag of drop-down menu to:

[select your-recipient "CEO|ceo@example.com"
                    "Sales|sales@example.com"
                    "Support|support@example.com"]

If you insert a pipe (‘|’) character in the middle of the option value, only the part before the pipe will be open to the outside, and the part after the pipe will be used for mail replacement.

pipe sample

You can use this usage of pipe only in the drop-down menu values, radio buttons or checkboxes. If you don’t like this feature, you may define the constant WPCF7_USE_PIPE as false to disable it.

8 responses to “Selectable Recipient with Pipes”

  1. Jon Eland

    This is great – thanks; one thing I would like to do thought – is to put the recipient name into the subject-line; is there a way I can extract the ‘label’ (before the pipe) rather than the ‘value’ (after the pipe) into an email.

    Thanks!

  2. k carey

    Is there a way to send multiple emails with Pipes… below is a code example I’m using… but I get an error when more than one person is selected. I’m using the WP-Mail-SMTP plugin in conjunction with ContactForm7.

    Your Name (required)
    [checkbox* your-name multiple

    "test|test@test.com"
    "test2|test2@test.com"
    "test3|test3@test.com"]

    Thanks!

  3. isabelle

    How can we add our own functions?
    I mean, for example, if zip code is 0000 then the email is sent to mr x, if the zip code is 1111 then to mister y.

    Any advice on doing this properly?

    Thanks in advance,

  4. Gab

    I love this feature. I’ve been a cforms user until recently, and I am VERY impressed with your plugin.

  5. Scott

    Would this feature support a lot of selections say several thousand