PHP code inside Contact form 7 Email template

2020-08-01 05:56发布

问题:

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:

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

}