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

 

您可以在此处添加自定义代码片段。有关详细信息,请参阅其他设置