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

 

您可以在此處新增自定義程式碼片段。有關詳細資訊,請參閱其他設定