PHP code inside Contact form 7 Email template

2020-08-01 06:03发布

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.

1条回答
看我几分像从前
2楼-- · 2020-08-01 06:30

This is possible by using the wpcf7_before_send_mail hook.

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

}
查看更多
登录 后发表回答