联系人表单7电子邮件模板中的PHP代码

联系人表单7电子邮件模板中的PHP代码

问题描述:

是否可以在联系表格7 电子邮件模板中插入PHP代码?我想在其中使页脚版权年度具有动态性。

Is there any way to insert PHP code inside contact form 7 Email Template? I want to make footer copyright year as dynamic in it.

这可以通过使用 wpcf7_before_send_mail来实现钩子。

在您的functions.php中,您可以使用以下代码:

In your functions.php you can use the following code:

add_action( 'wpcf7_before_send_mail', 'wpcf7_add_text_to_mail_body' );

function wpcf7_add_text_to_mail_body($contact_form){

    // get mail property
    $mail = $contact_form->prop( 'mail' ); // returns array with mail values

    // add date (or other content) to email body
    $mail['body'] .= date('Y');

    // set mail property with changed value(s)
    $contact_form->set_properties( array( 'mail' => $mail ) );

}