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.

Leave a Reply

Your email address will not be published. Required fields are marked *