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) 。

也可以看看