我正在尝试从自定义字段动态地获取收件人电子邮件,并使用字符串替换修改联系表格7的收件人电子邮件。联系表格正在发送,但似乎没有更改收件人电子邮件,因为我没有收到邮件。
<?php
function wpcf7_dynamic_email_field( $args ) {
$dynamic_email = '';
$submission = WPCF7_Submission::get_instance();
$unit_tag = $submission->get_meta( 'wpcf7-f3936-p3933-o1' );
// get the post ID from the unit tag
if ( $unit_tag && preg_match( '/^wpcf7-f(\d+)-p(\d+)-o(\d+)$/', $unit_tag, $matches ) ) {
$post_id = absint( $matches[2] );
$dynamic_email = get_post_meta( $post_id, 'email', true );
}
if ( $dynamic_email ) {
$args['recipient'] = str_replace('emailtoreplace@email.com', $dynamic_email, $args['recipient']);
}
return $args;
}
add_filter( 'wpcf7_mail_components', 'wpcf7_dynamic_email_field' );
?>
我正在使用CF7 4.5.1和PHP 5.3,这里有什么我漏掉的吗?