Special mail-tags

Special mail-tags

There may be times when you need more information than just the submitter』s input through contact form fields. For example, you may need to know the submitter』s IP address for security reasons. For such purposes, special mail-tags can be very helpful.

Unlike other mail-tags, special mail-tags are independent from form fields or the submitter』s input. You can place these special mail-tags anywhere mail-tags are allowed to be used, such as in the message body or other mail fields.

Special mail-tags for submissions#Special mail-tags for submissions

[_remote_ip] — This tag is replaced by the submitter』s IP address.

[_user_agent] — This tag is replaced by the submitter』s user agent (browser) information.

[_url] — This tag is replaced by the URL of the page in which the contact form is placed.

[_date] — This tag is replaced by the date of the submission.

[_time] — This tag is replaced by the time of the submission.

[_invalid_fields] — This tag is replaced by the number of form fields with invalid input.

[_serial_number] — This tag is replaced by a numeric string whose value increments, so this tag can work as the serial number of each submission. Requires Flamingo 1.5+ be installed.

Post-related special mail-tags#Post-related special mail-tags

These special mail-tags provide information about the post that contains the contact form.

Be aware that these [_post_*] tags work only when the contact form is placed inside post content. In cases where the contact form is outside of post content, such as when the contact form is placed in a sidebar widget or embedded in a theme』s template file, a blank text will replace the tag.

[_post_id] — This tag is replaced by the ID of the post.

[_post_name] — This tag is replaced by the name (slug) of the post.

[_post_title] — This tag is replaced by the title of the post.

[_post_url] — This tag is replaced by the permalink URL of the post.

[_post_author] — This tag is replaced by the author name of the post.

[_post_author_email] — This tag is replaced by the author email of the post.

Site-related special mail-tags#Site-related special mail-tags

These special mail-tags provide information about the WordPress website on which you manage the contact forms. You』ll find them especially useful when you want to reuse the same set of contact form templates between many websites, because you are freed from manual modification of the site information for each website.

[_site_title] — This tag is replaced by the title of the website.

[_site_description] — This tag is replaced by the description (tagline) of the website.

[_site_url] — This tag is replaced by the home URL of the website.

[_site_admin_email] — This tag is replaced by the email address of the primary admin user of the website.

User-related special mail-tags#User-related special mail-tags

These special mail-tags provide information about the current logged-in user.

Since these [_user_*] tags work only when the submitter has an account on the WordPress site and is logged in, it is recommended to turn on the subscribers-only mode setting anytime you use these tags.

If you want to use these tags but don』t want to use the subscribers-only mode, explicitly turn on the nonce setting. Otherwise, the logged-in user data will be reset by the WP REST API, and a blank text will replace the tag.

[_user_login] — This tag is replaced by the login name of the user.

[_user_email] — This tag is replaced by the email address of the user.

[_user_url] — This tag is replaced by the website URL of the user.

[_user_first_name] — This tag is replaced by the first name of the user.

[_user_last_name] — This tag is replaced by the last name of the user.

[_user_nickname] — This tag is replaced by the nickname of the user.

[_user_display_name] — This tag is replaced by the display name of the user.
Share this:FacebookTwitterLike this:Like Loading...

Controlling behavior by setting constants

Controlling behavior by setting constants

Contact Form 7 allows you to control its behavior by setting some constant values.

The typical place to define constants is in the wp-config.php file. You will find that many lines defining constants such as, define('XXX', 'xxx'); exist in the file. You can append new lines after them. Note that your lines must be placed before the last line.

Example (wp-config.php):

8081828384858687888990919293define( 'WP_DEBUG', false ); define ( 'WPCF7_LOAD_JS', false ); // Added to disable JS loadingdefine ( 'WPCF7_LOAD_CSS', false ); // Added to disable CSS loading /* That's all, stop editing! Happy publishing. */ /** Absolute path to the WordPress directory. */if ( ! defined( 'ABSPATH' ) ) {    define( 'ABSPATH', __DIR__ . '/' );} /** Sets up WordPress vars and included files. */require_once ABSPATH . 'wp-settings.php';

The rest of this post describes a variety of constants.

WPCF7_LOAD_JS

When the value of this constant is false (default: true), Contact Form 7 does not load the JavaScript on the front end. When the value of this constant is set as header, Contact Form 7 loads the JavaScript in the header instead of in the footer (default).

See also: Loading JavaScript and stylesheet only when it is necessary

WPCF7_LOAD_CSS

When the value of this constant is false (default: true), Contact Form 7 does not load the CSS stylesheet on the front end.

See also: Loading JavaScript and stylesheet only when it is necessary

WPCF7_AUTOP

When the value of this constant is false (default: true), Contact Form 7 does not apply the 「autop」 filter to the form content. The 「autop」 filter replaces double line-breaks with paragraph elements.

WPCF7_USE_PIPE

When the value of this constant is false (default: true), Contact Form 7 disables its 「pipe」 feature, so that pipe character has no special meaning.

See also: Selectable recipient with pipes

WPCF7_ADMIN_READ_CAPABILITY

The value of this constant holds the minimum capability required for access to the administration panel. The default value is edit_posts.

See also: Restricting access to the administration panel

WPCF7_ADMIN_READ_WRITE_CAPABILITY

The value of this constant holds the minimum capability required for editing contact forms. The default value is publish_pages. Obviously WPCF7_ADMIN_READ_WRITE_CAPABILITY should be stricter than WPCF7_ADMIN_READ_CAPABILITY, as you cannot edit contact forms without accessing the administration panel.

See also: Restricting access to the administration panel

WPCF7_UPLOADS_TMP_DIR

When this constant is defined, the value of the constant overrides the setting of directory path of the temporary folder for uploaded files.

See also: File uploading and attachment
Share this:FacebookTwitterLike this:Like Loading...

Redirecting to another URL after submissions

Redirecting to another URL after submissions

First of all, I believe that this tip I』m writing on this post is not necessary for 99.99% of users and, actually, I don』t recommend using it. I』m writing this for the 0.01% of you, so you can ignore it if not necessary.

As you know, Contact Form 7 redirects to the same URL as the form』s URL after form submissions in the default settings. However, in very rare cases, you might need to change this to make it redirect to another URL after submissions. I』ll write in this post how you can set up Contact Form 7 to do just that.

By the way, I』m often asked by users that how they can redirect to so-called 「Thank You Page」. In most cases, they want to know it because they assume that redirecting to 「Thank You Page」 is necessary for tracking form submissions with Google Analytics. That』s not necessary at all. In fact, it』s an outdated and nonsense custom. Today you can track submissions with Google Analytics without any redirection.

So you have other reason for redirecting to another URL?

The simplest way is utilizing Contact Form 7』s custom DOM event to run JavaScript. The following is an example of script that redirects you to another URL when the wpcf7mailsent event occurs:

document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'http://example.com/';
}, false );

Embed this snippet into your theme』s template file. Obviously, you need to replace the http://example.com/ in the code to the URL you want to redirect to.

Note: The method using on_sent_ok hook is no longer recommended.
Share this:FacebookTwitterLike this:Like Loading...

Disallowed list (formerly known as 「Comment blacklist」)

Disallowed list (formerly known as 「Comment blacklist」)

If you are suffering from an influx of spam or unwanted messages through contact forms and you can』t block them completely by using reCAPTCHA or Akismet, the disallowed list feature will be of great help to you.

The disallowed list is originally a feature of WordPress to help manage comments. Contact Form 7 can also utilize it to blocklist specific words or IP addresses.

Disallowed list is quite simple to use; just log-into the WordPress admin screen, move to the menu Settings > Discussion, and then you』ll find the Disallowed Comment Keys section in the middle of the screen.

The Disallowed Comment Keys section in Settings > Discussion

Put one word or IP address per line in the text box. Messages containing the word or sent from the IP address in the list you』ve created will be treated as spam by Contact Form 7 and will not be delivered.

How can you get the IP address from which the messages originate? The simplest method is by using the special mail-tag [_remote_ip] in the content of the email sent to you. It will show the sender』s IP address.
Share this:FacebookTwitterLike this:Like Loading...

Save submitted messages with Flamingo

Save submitted messages with Flamingo

Contact Form 7 doesn』t store submitted messages anywhere. Therefore, you may lose important messages forever if your mail server has issues or you make a mistake in mail configuration.

Install a message storage plugin before this happens to you. Flamingo saves all messages through contact forms into the database. Flamingo is a free WordPress plugin created by the same author as Contact Form 7.

» Download Flamingo plugin from WordPress.org

Customizing Subject and From fields in messages#Customizing Subject and From fields in messages

In the Inbound Messages admin menu, you will see there are Subject and From fields. Those fields have the message』s subject, and submitter』s name and email address respectively.

By default, those fields retrieve values from Contact Form 7』s default input fields: your-subject, your-name, and your-email. Therefore, if you have modified your contact form and it doesn』t have the default input fields, the Subject and From fields don』t show correct values.

In such cases, try customizing those fields as the following:

Open the Additional Settings tab in the contact form editor page, and add lines like these:

flamingo_email: "[the-email-field]"
flamingo_name: "[the-name-field]"
flamingo_subject: "[the-subject-field]"

You can use plain text and mail-tags in the value for each line. You can also use multiple mail-tags in a line; if you have input fields for first name and last name instead of a single name field, you may want to set up the flamingo_name like this:

flamingo_name: "[first-name-field] [last-name-field]"
Share this:FacebookTwitterLike this:Like Loading...

reCAPTCHA (v3) 驗證碼

reCAPTCHA (v3) 驗證碼

reCAPTCHA 保護您免受垃圾郵件和其他類型的自動濫用。使用 Contact Form 7 的 reCAPTCHA 集成模塊,您可以阻止垃圾郵件機器人提交的濫用表單。

reCAPTCHA API 的最新版本是 v3 。聯繫表格 7 5.1 及更高版本使用此 reCAPTCHA v3 API 。 reCAPTCHA v3 在後台運行,因此用户無需閲讀圖像中的模糊文本,甚至無需勾選 「我不是機器人」 複選框。

注意: reCAPTCHA v3 的 API 密鑰與 v2 的不同;v2 的密鑰不適用於 v3 API 。您需要再次註冊您的站點以獲取 v3 的新密鑰。

如果您使用的是舊版本的 Contact Form 7,並且正在尋找有關 v2 API 的 reCAPTCHA 模塊的信息,請參閲 reCAPTCHA (v2)

註冊網站

要開始使用 reCAPTCHA,您首先需要註冊 WordPress 站點。 reCAPTCHA 是 Google 的服務,因此您需要一個 Google 帳户才能使用它。使用該帳户登錄 Google,然後轉到我的 reCAPTCHA 頁面。您將看到一個簡單的註冊表,如下所示:

我的 reCAPTCHA 頁面的屏幕截圖
我的 reCAPTCHA 頁面

從類型選項中選擇 reCAPTCHA v3,然後在域字段中輸入網站的域。

註冊網站後,您將獲得該網站的站點密鑰和秘密密鑰。

reCAPTCHA 站點詳細信息的屏幕截圖,包括站點密鑰和密鑰
網站詳情

接下來,移至 WordPress 管理屏幕並打開聯繫人 > 集成菜單頁面。

集成菜單頁面的屏幕截圖
集成菜單頁面

您將在那裏看到一個名為 reCAPTCHA 的框。單擊框中的設置集成。它將顯示輸入字段 Site Key 和 Secret Key 。將您在上一步中收到的兩個密鑰複製粘貼到字段中,然後點擊保存更改。

輸入 API 密鑰後集成頁面的屏幕截圖
輸入 API 密鑰
現在,您的聯繫表單使用 reCAPTCHA 的分數來驗證表單提交是來自人類還是垃圾郵件機器人。

reCAPTCHA v3 不需要驗證碼小部件 (reCAPTCHA v2 中使用的 「我不是機器人」 複選框) 即可工作,因此 [recaptcha] 不再需要表單標籤。如果 [recaptcha] 在表單模板中找到表單標籤,Contact Form 7 5.1 或更高版本將忽略它們並用空字符串替換它們。

也可以看看

Sendinblue 集成

Sendinblue 集成

披露:這篇文章的作者是 Sendinblue 的附屬機構,這意味着如果您決定通過插件作者的鏈接進行購買,插件作者將獲得佣金,您無需支付任何費用。

Sendinblue 標誌

 

在歐洲領先的 CRM 和電子郵件營銷平台 Sendinblue 上存儲和組織您的聯繫人,同時保護用户隱私。 Sendinblue 提供無限的聯繫方式和高級營銷功能。

  1. 連接到 API
  2. 設置您的聯繫表格
  3. 聯繫人屬性-表單字段映射
  4. 隱私考慮

連接到 API

此集成模塊使用 Sendinblue API (v3) 。要訪問 API,您需要一個 Sendinblue 帳户。如果您還沒有,請先創建一個免費帳户。您可以隨時升級帳户。

創建帳户後,登錄 Sendinblue 儀表板並導航到 SMTP & API 頁面。你會在那裏找到你的 v3 API 密鑰。這個密鑰在下一步中使用,所以現在複製它。

「SMTP & API」頁面的屏幕截圖
「SMTP & API」 頁面的屏幕截圖

 

然後打開一個新的瀏覽器選項卡並登錄到您的 WordPress 儀表板。導航到聯繫人 > 集成菜單頁面,然後單擊 Sendinblue 框中的設置集成。您會在那裏找到一個輸入字段。將 API 密鑰粘貼到該字段中,然後單擊 Save changes 。

集成頁面的屏幕截圖
集成頁面的屏幕截圖

 

現在 Sendinblue API 可通過您的聯繫表格獲得。下一步是設置每個聯繫表格。

設置您的聯繫表格

激活 Sendinblue API 後,您將在聯繫表單編輯器屏幕中找到一個新創建的選項卡。使用這個 Sendinblue 選項卡面板,您可以控制這個集成模塊的兩個主要功能:聯繫人列表和歡迎電子郵件。

Sendinblue 選項卡面板的屏幕截圖
Sendinblue 選項卡面板的屏幕截圖

 

如果選中 「聯繫人列表」 複選框,則提交者將在提交聯繫表單後添加到您的聯繫人列表中。您還可以指明聯繫人將添加到哪些列表中。

如果選中歡迎電子郵件複選框,聯繫表 7 將向新聯繫人發送歡迎電子郵件。僅當提交者成功添加到聯繫人列表時才會發送歡迎電子郵件。

歡迎電子郵件使用 Sendinblue 的電子郵件模板系統,可讓您撰寫完全個性化、優雅的 HTML 電子郵件。此外,電子郵件是通過 Sendinblue 可靠的 SMTP 基礎設施傳送的,這使您可以在發送後跟蹤電子郵件的狀態。

注意:聯繫表 7 僅使用 Sendinblue 的 SMTP 作為新聯繫人的歡迎電子郵件。歡迎電子郵件以外的電子郵件使用 WordPress 的內置 wp_mail() 功能。如果您想對 WordPress 上的每封電子郵件使用 Sendinblue 的 SMTP,請安裝 Sendinblue 的官方 WordPress 插件

聯繫人屬性-表單字段映射

Sendinblue 的聯繫人數據由四個基本屬性 (EMAIL 、 FIRSTNAME 、 LASTNAME 和 SMS) 和用户定義的附加屬性組成。當您根據表單提交創建新聯繫人時,將從用户輸入值中檢索這些聯繫人屬性。

例如,從 「您的電子郵件」 字段中檢索 EMAIL 屬性。以同樣的方式,從名稱包含 「your-」 前綴+小寫的屬性名稱的表單字段中檢索屬性。

此外,FIRSTNAME 和 LASTNAME 有一個特殊的映射規則。對於表單不包含 「您的名字」 或 「您的姓氏」 字段而是包含 「您的姓名」 字段的情況,「您的姓名」 字段值的第一個單詞用於 FIRSTNAME 屬性,其餘部分用於 LASTNAME 屬性。因此,例如,如果在 「您的姓名」 字段中輸入 「文森特·梵高」,則 FIRSTNAME 將是 「Vincent」,而 LASTNAME 將是 「van Gogh」 。

另請注意,必須將 SMS 屬性值指定為具有正確國家/地區代碼的國際電話號碼(例如:+91xxxxxxxxxx 或 0091xxxxxxxxxx) 。如果您有 SMS 的輸入字段並且用户輸入的格式不正確,則創建聯繫人的 API 請求將失敗。

電子郵件模板中使用參數遵循相同的映射規則。如果您 {{ params.SIZE }} 的電子郵件模板中有佔位符,則 「您的大小」 字段值將替換電子郵件中的佔位符。

最後,您可以使用 wpcf7_sendinblue_collect_parameters 過濾器鈎子自定義整個映射。

隱私考慮

強烈建議您在將他們的個人數據添加到您的聯繫人列表之前獲得表單提交者的明確同意。未經同意收集個人數據不僅是非法的,而且如果將電子郵件發送給非預期的接收者,也可能導致垃圾郵件投訴率很高。

聯繫表格 7 提供了 consent_for:sendinblue 表單標籤選項來檢查提交者的同意,下面提供了一個例子:

[acceptance your-consent optional consent_for:sendinblue]  It's OK to add me to your contact list.  [/acceptance]

如果您的聯繫表單中有此表單標記 (接受複選框),則僅當提交者選中該複選框以確認他們的同意時,聯繫表單 7 才會將聯繫數據發送到 Sendinblue API 。

Getting default values from shortcode attributes

Getting default values from shortcode attributes

Sometimes you may feel that it would be useful if you could use values from [contact-form-7 ...] shortcode attributes.

In such cases, you can use the default:shortcode_attr form-tag option, which retrieves the field default value from shortcode attributes.

For example, let』s say you have a field named 「destination-email」 for the destination email address:

[email* destination-email]

To get the default value from shortcode attributes, add the default:shortcode_attr option to the form-tag:

[email* destination-email default:shortcode_attr]

Then, add an attribute with the same name as the field (「destination-email」 in this case) into the shortcode for the contact form:

[contact-form-7 id="123" title="Contact Form" destination-email="[email protected]"]

Is that all? Unfortunately, no; there is a necessary extra step.

Normally, a WordPress shortcode only takes predefined attributes, so you need to register the attribute beforehand.

Add the following code snippet to your theme』s functions.php file:

add_filter( 'shortcode_atts_wpcf7', 'custom_shortcode_atts_wpcf7_filter', 10, 3 );

function custom_shortcode_atts_wpcf7_filter( $out, $pairs, $atts ) {
$my_attr = 'destination-email';

if ( isset( $atts[$my_attr] ) ) {
$out[$my_attr] = $atts[$my_attr];
}

return $out;
}

That』s all! You』ll see 「[email protected]」 input in the field.
Share this:FacebookTwitterLike this:Like Loading...

Setting default values to the logged-in user

Setting default values to the logged-in user

You may need to create a contact form targeted at users with accounts on your WordPress site. You already have basic information about the user (name, e-mail, etc.) so asking users for this would be redundant.

You can set the logged-in user』s information as the default value by adding several options to a text field.

OptionDescriptiondefault:user_loginUser』s login namedefault:user_emailUser』s email addressdefault:user_urlUser』s site URLdefault:user_first_nameUser』s first namedefault:user_last_nameUser』s last namedefault:user_nicknameUser』s nicknamedefault:user_display_nameUser』s display name

Example:

Your Name: [text* your-name default:user_display_name]
Your E-mail: [email* your-email default:user_email]

Users who are logged in will notice that the basic information is already completed.
Share this:FacebookTwitterLike this:Like Loading...

管理員畫面

管理員畫面
編輯器屏幕截圖 1

 

此聯繫表的標題 (❶) 。此標題只是聯繫表格的標籤,僅用於管理目的。您可以使用任何您喜歡的標題,例如 「求職申請表」 、 「2014/02/14 活動表格」 等。

此聯繫表格的簡碼 (❷) 。複製此代碼並將其粘貼到您要放置此聯繫表單的帖子、頁面或文本小部件內容中。

您可以在此處保存、複製或刪除此聯繫表格 (❸) 。

表格選項卡

編輯器屏幕 2 的屏幕截圖

 

表格編輯欄 (❷) 。您可以在此處使用 HTML 和 form-tags 自定義表單內容。此字段中的換行符和空行會自動使用<br /> 和<p>HTML 標記進行格式化。

標籤生成器 (❶) 。通過使用這些標籤生成器,您可以在不瞭解它們的情況下生成表單標籤

有關表單標籤的更多信息,請參閲編輯表單模板標籤的工作原理

郵件標籤

編輯器屏幕 3 的屏幕截圖

 

您可以編輯作為表單提交結果發送的郵件的郵件模板。您可以在這些字段中使用郵件標籤

Mail(2) 模板是一個附加的郵件模板,它可以具有與主郵件模板不同的內容,也可用。

有關更多信息,請參閲設置郵件

消息選項卡

編輯器屏幕 4 的屏幕截圖

 

您可以編輯用於各種情況的消息,包括 「發生驗證錯誤」 、 「請填寫必填字段」 等。

請注意,此處僅提供純文本。不允許在消息字段中使用 HTML 標記和實體。

有關更多信息,請參閲編輯消息

附加設置選項卡

編輯器屏幕截圖 5

 

您可以在此處添加自定義代碼片段。有關詳細信息,請參閲其他設置