Adding Cc, Bcc and other mail headers

Adding Cc, Bcc and other mail headers

Contact Form 7 has setting fields for mail headers of To, From and Subject. Have you ever thought of adding Cc or Bcc headers to your email? Additional Headers fields in the Mail and Mail (2) sections are just for that purpose.

You can input any header lines into the field; and you can insert any mail-tags into any place in each header line, just like other Mail fields.

Share this:FacebookTwitterLike this:Like Loading...

Restricting access to the administration panel

Restricting access to the administration panel

In its default settings, Contact Form 7 allows all users except subscriber users to have access to the administration panel; but allows only administrator and editor users to edit contact forms. You might feel that you would want to change this setting to restrict access even more, so I will show you how to do this in this article.

For example, let』s change access to allow only administrator users access and editing rights. You can do this by editing your wp-config.php and inserting these lines:

define( 'WPCF7_ADMIN_READ_CAPABILITY', 'manage_options' );
define( 'WPCF7_ADMIN_READ_WRITE_CAPABILITY', 'manage_options' );

WPCF7_ADMIN_READ_CAPABILITY holds the minimum capability required for access to the administration panel, while WPCF7_ADMIN_READ_WRITE_CAPABILITY holds the minimum capability required for editing contact forms. 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.

manage_options is a capability that normally only administrator users have. So setting manage_options to both WPCF7_ADMIN_READ_CAPABILITY and WPCF7_ADMIN_READ_WRITE_CAPABILITY allows only those administrator users access and editing rights.

You can set any capabilities you wish to these constants to fine-tune the restrictions. If you want to learn further about WordPress』 Roles and Capabilities concepts, and to learn more about what capabilities are available, check WordPress support document.
Share this:FacebookTwitterLike this:Like Loading...

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...

Contact form in your language

Contact form in your language

You don』t need extra multilingual plugins to manage contact forms in your language. By going to the WordPress admin screen (WordPress has a standardized localization mechanism), you can switch the language used in the contact form editor user interface and you can switch the language used for the default template for newly created contact forms.

Localizing contact form editor UI

To switch the language used for admin screens, move to Users > Your Profile admin menu page. You』ll find the language selector there.

The language used for the screens under the Contact menu will follow your language setting. If not, make sure that: 1) a language pack for the language is available on the translate.wordpress.org site, and 2) the latest version of the language pack is installed on your site.

Localizing default contact form template

After setting the UI language, move to Contact > Add New menu page to create a new contact form. If both the UI language and the language pack for Contact Form 7 have been correctly set up, the contents in the Form, Mail, and Messages tab panels should be localized for your language. If not, once again, make sure the latest language pack is installed.

If you find the language pack for your language isn』t available yet or isn』t maintained well, it』s time to contribute to the plugin translation.
Share this:FacebookTwitterLike this:Like Loading...

Custom layout for checkboxes and radio buttons

Custom layout for checkboxes and radio buttons

In its default settings, Contact Form 7 renders checkboxes and radio buttons as inline boxes. You can customize this using some form-tag options and simple CSS.

Reversing checkbox-label order

By default, Contact Form 7 renders a checkbox in front of its label like the following:

You can reverse this order by adding label_first option to the checkbox tag.

[checkbox your-cb label_first "Option 1" "Option 2" "Option 3"]

Rendering checkboxes as block instead of original inline

To render checkboxes as block boxes, add a line of CSS style rule to your theme』s stylesheet:

1span.wpcf7-list-item { display: block; }

Rendering checkboxes as a table

To render checkboxes as a table, add these CSS style rules to your theme』s stylesheet:

12span.wpcf7-list-item { display: table-row; }span.wpcf7-list-item * { display: table-cell; }

(Combined with label_first option)

See also

Checkboxes, radio buttons and menusStyling contact form

Share this:FacebookTwitterLike this:Like Loading...

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 。

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...

Loading JavaScript and stylesheet only when it is necessary

Loading JavaScript and stylesheet only when it is necessary

In its default settings, Contact Form 7 loads its JavaScript and CSS stylesheet on every page. You might think it would be redundant or wasteful, and want to load them only on those pages that contain contact forms. I understand the feeling, but there is a technical difficulty for a plugin in knowing whether the page contains contact forms or not at the start of loading. However, I can show you a way to work around that.

Step 1: Stop loading the JavaScript and CSS stylesheet on all pages

When the value of WPCF7_LOAD_JS is set to false (default: true), Contact Form 7 does not load the JavaScript. You can set the value of this constant in your wp-config.php like this:

define( 'WPCF7_LOAD_JS', false );

Likewise, you can control the loading of the CSS stylesheet with WPCF7_LOAD_CSS. Contact Form 7 does not load the CSS stylesheet when the value of WPCF7_LOAD_CSS is false (default: true). You can set it in the wp-config.php like this:

define( 'WPCF7_LOAD_CSS', false );

Or, you can also disable the loading of the JavaScript and CSS by adding a few lines of code into your theme』s functions.php file, like this:

add_filter( 'wpcf7_load_js', '__return_false' );
add_filter( 'wpcf7_load_css', '__return_false' );

Now you have succeeded in stopping the loading of the JavaScript and CSS stylesheet, but, unfortunately, you』ve also killed them on pages that contain contact forms — so we really need to get them back on the right pages. So, the next step is what you』ll need to load the files on to the explicit pages in which you need them.

Step 2: Load the files on pages which contain contact forms

For example, let』s say you have a page named 「Contact」 and it is the only page that contains a contact form. And suppose that you have a template file for the 「Contact」 page named 『contact.php』 in your theme folder. Now you will need to load Contact Form 7』s JavaScript and CSS stylesheet specifically on the 「Contact」 page.

To do this, you must edit the 『contact.php』 template file and insert the following lines into it:

Note that wpcf7_enqueue_scripts() and wpcf7_enqueue_styles() must be called before wp_head() is called.
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 或更高版本將忽略它們並用空字串替換它們。

也可以看看

設定郵件

設定郵件

您可以非常靈活地編輯電子郵件模板。不僅是郵件正文,您還可以編輯郵件標題欄位。如果需要,您甚至可以在訊息中使用 HTML 。

您可以在 「郵件」 選項卡面板中編輯電子郵件模板。

郵件選項卡的螢幕截圖
郵件標籤面板

欄位到場

在此處設定收件人電子郵件地址。您可以在此欄位中使用郵件標籤

在有效的郵箱語法中指定值,否則您將收到配置錯誤

從欄位來自外地

在此處設定發件人電子郵件地址。您可以在此欄位中使用郵件標籤

此欄位值應該是與網站屬於同一域的電子郵件地址。否則你會得到一個配置錯誤

主題欄位學科領域

在這裡設定訊息的主題。您可以在此欄位中使用郵件標籤

附加標題附加標題

您可以在此處插入其他訊息頭欄位,例如 Cc 和 Bcc 。每行應該有一個欄位。您可以在這些欄位中的任何位置嵌入郵件標籤

訊息正文郵件正文

這是訊息體;您可以在該欄位的任何位置嵌入郵件標籤

如果您選中從輸出中排除帶有空白郵件標籤的行復選框,則包含具有空值的郵件標籤的行將從實際電子郵件輸出的郵件正文中排除。

預設情況下,純文字用於訊息正文。要使用 HTML,請選中使用 HTML 內容型別覈取方塊。

檔案附件檔案附件

如果您將上傳的檔案附加到此電子郵件,請將上傳檔案的郵件標籤放入檔案附件欄位。您還可以從伺服器附加檔案 (本地檔案附件) 。

郵件 (2) 郵件 (2)

郵件 (2) 是一個附加的郵件模板。它通常用作自動回覆器,但您可以將其用於任何目的。僅當主郵件已成功傳送時才傳送郵件 (2) 。

也可以看看