gpt4 book ai didi

php - 联系表格 7 - 动态收件人电子邮件

转载 作者:可可西里 更新时间:2023-10-31 23:45:36 24 4
gpt4 key购买 nike

我正在尝试从自定义字段中动态获取收件人电子邮件,并使用字符串替换来修改联系表 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,我在这里遗漏了什么吗?

最佳答案

要向动态收件人发送电子邮件 wince WPCF7 5.2,我是这样做的:

function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {

$dynamic_email = 'email@email.com'; // get your email address...

$properties = $contact_form->get_properties();
$properties['mail']['recipient'] = $dynamic_email;
$contact_form->set_properties($properties);

return $contact_form;

}
add_filter( 'wpcf7_before_send_mail', 'wpcf7_before_send_mail_function', 10, 3 );

关于php - 联系表格 7 - 动态收件人电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39953217/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com