doujia5863 2019-07-12 20:00
浏览 149

使用高级自定义字段值作为联系表单7中的“电子邮件地址”

I'm creating a page in which you submit a Contact Form 7 to the email based on what email is added to the job_email field via my Advanced Custom Fields.

enter image description here

I have attempted to add the form via the PHP shortcode like this

[email* dynamic-email class:email-address placeholder "Email Address*"]

echo do_shortcode('[contact-form-7 id="234" title="Dynamic Submit CV" dynamic-email="'.get_field( 'job_email' ).'"]' );

The fields all display correctly, and upon submitting the email successfully, the email never receives the form. Meaning I am totally missing something here.

  • 写回答

1条回答 默认 最新

  • douyu0845 2019-07-13 22:19
    关注

    If I understand correctly, what you are after is send a notification with the entry details to the email address inputted on the job_email field.

    If so, what you want to do is to set up an email on the email tab and in the To: setting put [job_email].

    Update

    As you stated in the comment, the email has to be the one set in the backend. You can guarantee the email notification to be sent to the ACF-based email via hooks, specifically the wpcf7_mail_components hook.

    function so57013385_mail_components( $components, $number ) {
        $job_mail = get_field( ... );
    
        $components['recipient']   = (array) $components['recipient'];
        $components['recipient'][] = $job_mail;
    
        return $components;
    };
    add_filter( 'wpcf7_mail_components', 'so57013385_mail_components', 10, 2 );
    

    Note: I'm casting the $components['recipient'] variable to array just to make sure the email is appended correctly, as this parameter is passed directly to wp_mail(), which can receive a string or an array. Also, you might need to add more validations on the form ID, sanitization, etc. The above code is not tested.

    评论

报告相同问题?

悬赏问题

  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图