在联系表 7 中加载终极会员动态电子邮件发送电子邮件

发布于 2025-01-12 15:21:47 字数 2583 浏览 0 评论 0原文

我正在使用 Ultimate Member 插件,我需要 CF7 加载每个用户的电子邮件以发送这些用户的公共配置文件中的成员。 在这里,我留下了我使用过的代码,但它仅适用于我,如果我以字符串格式输入电子邮件, $dynamic_email = '[电子邮件受保护]'; 而不是$dynamic_email = $value; 如何使以下动态代码为我工作?

function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {
        $form_id = $contact_form->id();
        if($form_id == 799 ){
            $valor = get_the_author_meta('user_email', um_profile_id()); // um_profile_id() - Profile ID in the Ultimate Member plugin
            $dynamic_email = $valor;
            $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 );

我需要加载 get_the_author_meta('user_email', um_profile_id()) 的值,以便在每个公共配置文件中上传邮件。

非常感谢您的帮助。

总结此功能如果有效,它会设法更改发送电子邮件并发送表单:

function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {
        $form_id = $contact_form->id();
        if($form_id == 799 ){
            $dynamic_email = '[email protected]';
            $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 );

我需要的另一个功能不起作用,并且不会发送显示错误“尝试发送消息时发生错误”的邮件请稍后再试。”我不明白或不知道为什么它不起作用,如果我只做一个小的改变,它也会返回一封电子邮件:

function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {
        $form_id = $contact_form->id();
        if($form_id == 799 ){
            $valor = get_the_author_meta('user_email', um_profile_id()); // um_profile_id() - Profile ID in the Ultimate Member plugin
            $dynamic_email = $valor;
            $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 );

感谢您的帮助。

I am using the Ultimate Member plugin and I need CF7 to load the email of each user for sending that are within the public profiles that are the members.
Here I leave the code that I have used but it only works for me if I put an email in string format, $dynamic_email = '[email protected]'; instead of $dynamic_email = $value;
How do I make the following dynamic code work for me?

function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {
        $form_id = $contact_form->id();
        if($form_id == 799 ){
            $valor = get_the_author_meta('user_email', um_profile_id()); // um_profile_id() - Profile ID in the Ultimate Member plugin
            $dynamic_email = $valor;
            $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 );

I need to load the value of get_the_author_meta('user_email', um_profile_id()) so that I upload the mail in each of the public profiles.

Thank you very much for the help.

Summarizing this function if it works, it manages to change the sending email and sends the form:

function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {
        $form_id = $contact_form->id();
        if($form_id == 799 ){
            $dynamic_email = '[email protected]';
            $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 );

This other one that is the one I need does not work and does not send the mail showing the error "An error occurred while trying to send your message. Please try again later." and I do not understand or know the reason why it does not work if I only make a small change and it also returns an email:

function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {
        $form_id = $contact_form->id();
        if($form_id == 799 ){
            $valor = get_the_author_meta('user_email', um_profile_id()); // um_profile_id() - Profile ID in the Ultimate Member plugin
            $dynamic_email = $valor;
            $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 );

Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

臻嫒无言 2025-01-19 15:21:47

要将 um_profile_id() 传递给表单数据,您需要将其添加到表单中(如我自己和@cbroe 的评论中所述)。为此,您需要使用 JavaScript 将其传递到隐藏的表单字段,或者只是创建一个自定义表单标记。下面使用自定义表单标签。

[um_profile_id] 添加到您的表单中,以下功能将起作用。

此外,由于 wpcf7_before_send_mail 是一个操作挂钩,您不必返回任何内容,因此 $contact_form 对象通过引用传递,并在您设置属性时更新。

function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {
    if ( $submission && 799 === $contact_form->id() ) {
        $posted_data = $submission->get_posted_data();
        if ( isset( $posted_data['um-profile-id'] ) ) {
            $user                            = get_user_by( 'id', absint( $posted_data['um-profile-id'] ) );
            $properties                      = $contact_form->get_properties();
            $properties['mail']['recipient'] = $user->user_email;
            $contact_form->set_properties( $properties );
        }
    }
}
add_action( 'wpcf7_before_send_mail', 'wpcf7_before_send_mail_function', 10, 3 );


add_action( 'wpcf7_init', 'um_profile_id_form_tag' );
function um_profile_id_form_tag() {
    wpcf7_add_form_tag( 'um_profile_id', 'cf7_get_um_profile_id' );
}

function cf7_get_um_profile_id() {
    $output = sprintf( '<input type="hidden" name="um-profile-id" value="%s"/>', um_profile_id() );
    return $output;
}

该方法已经过测试并且有效。

To pass the um_profile_id() to the form data, you need to add it to the form (as stated in the comments by myself and @cbroe). To do that, either you need to pass it using javascript to a hidden form field, or simply create a custom form tag. Below uses a custom form tag.

Add [um_profile_id] to your form, and the below function will work.

Additionally, since wpcf7_before_send_mail is an action hook you don't have to return anything, the $contact_form object is passed by reference and updated when you set the property.

function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {
    if ( $submission && 799 === $contact_form->id() ) {
        $posted_data = $submission->get_posted_data();
        if ( isset( $posted_data['um-profile-id'] ) ) {
            $user                            = get_user_by( 'id', absint( $posted_data['um-profile-id'] ) );
            $properties                      = $contact_form->get_properties();
            $properties['mail']['recipient'] = $user->user_email;
            $contact_form->set_properties( $properties );
        }
    }
}
add_action( 'wpcf7_before_send_mail', 'wpcf7_before_send_mail_function', 10, 3 );


add_action( 'wpcf7_init', 'um_profile_id_form_tag' );
function um_profile_id_form_tag() {
    wpcf7_add_form_tag( 'um_profile_id', 'cf7_get_um_profile_id' );
}

function cf7_get_um_profile_id() {
    $output = sprintf( '<input type="hidden" name="um-profile-id" value="%s"/>', um_profile_id() );
    return $output;
}

This method has been tested and works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文