Setting the ‘to:’ address in Contact Form 7 from a custom field

This does assume you have the Contact Form 7 and Dynamic Text Extension plugins installed. If you don’t, this article will mean bugger all.

On our works web site, we use Contact Form 7, about 30 in all, and after being asked to change the ‘to:’ address once too often, I thought ‘fuck this’ and came up with a solution where the content editors can do it themselves without pestering me all the time.

The quickest way is to simply set a custom field on the page/post you want the Contact Form 7 to appear on. At the bottom of the editor screen, there is the option to Add New Custom Field. For the sake of this tutorial, I’m going to call the key cf_email_to_address and then enter the email address you want to test.

Click Update or Save depending on what you’re doing, and now head over to the Contact Form 7 that you want to edit and in the Form tab, add this at the top:

[dynamichidden recipient-email "CF7_get_custom_field key='cf7_email_to_address' obfuscate='on'"]

This is a CF7 dynamic field that put the value of the custom field cf7_email_to_address that we created above, and puts it into variable recipient-email.

All we have to do now is click on the Mail tab and in the To address, add this:

[_post_title] <[recipient-email]>

Will send an email with the post title name to the email address we specified in the custom field.

Simple.


About SarkyMarky

Developer, coder, graphics, blogger, podcaster, avid reader, science geek and history nerd living in deepest darkest Devon Armored Warfare : SarkyMarky World of Tanks + Blitz ; SarkyMarky Steam : markhall1971 Instagram : markhall1971_ Viber : *Ask* WhatsApp : *Ask* Skype : sarky-marky Snapchat : *Ask*

3 comments:

  1. Thanks for your solution,
    but adding [_post_title]
    in To address, give me an “An invalid e-mail address syntax.”

    i’v tried also with

    [recipient-email]
    [recipient-email]

    Seems not to accept the fact that the shortcode does not contain a valid email address

    this is my module:
    ——————————–
    [dynamictext recipient-email “CF7_get_custom_field key=’user_email'”]

    [text* campo-nome “Nome”]
    [email* campo-email “La tua email”]
    [textarea campo-messaggio “Spet.le Mediocredito Centrale..”]
    [submit “Invia messaggio”]

    Any solution?
    thanks

    1. oh i’m sorry, i cant add some tags commenting your post like
      it was:
      adding [_post_title] left arrow [recipient-email] right arrow
      in To address, give me an “An invalid e-mail address syntax.”

Leave a Reply