【问题标题】:CF7 need to send two different mailCF7需要发送两个不同的邮件
【发布时间】:2017-02-23 10:57:30
【问题描述】:

我创建了一个包含联系表 7 的表单,我需要发送两封电子邮件,一封包含我从表单中获取的所有数据,另一封包含“谢谢”消息和其他重要信息,这些信息是静态的,对于每个点击提交按钮的用户来说都是一样的。

所以我的问题是这封电子邮件,CF7 只能向多个用户发送一种类型的邮件,但不能向两个不同的用户发送两封不同的邮件。第二封邮件需要使用 [your-mail](用户在表单中填写的邮件)。

我发现了允许我在提交后打开页面或其他内容的 on_sent_ok 功能,但我不知道如何发送不同的邮件。

【问题讨论】:

    标签: wordpress email


    【解决方案1】:

    您的请求已经有一段时间了,但我在这里写下我的解决方案以满足未来的需求。

    您可以通过以下 2 个步骤达到目标:

    A) 处理已发送邮件 Contact Form 7 事件。

        function your_wpcf7_mail_sent_function( $contact_form ) {
            $title = $contact_form->title;
            $submission = WPCF7_Submission::get_instance();
            if ($submission && "New hospital" == $title) {
                $posted_data = $submission->get_posted_data();
                //$posted_data is an associative array that contains all the form input values,
                //so you can use it to proceed with B step
           }
        }
    
    add_action( 'wpcf7_mail_sent', 'wpcf7_mail_sent_event_triggered' );
    

    如果您不确定此代码的位置,我的建议是将其添加到主题的 function.php 文件的开头。

    B) 使用wp_mail API 发送自定义邮件。 如果您查看文档,您会发现 API 非常容易理解。

    $to = 'sendto@example.com';
    $subject = 'The subject';
    $body = 'The email body content';
    $headers = array('Content-Type: text/html; charset=UTF-8');
    
    wp_mail( $to, $subject, $body, $headers );
    

    显然,您可以根据需要使用或不使用 $posted_data 值自定义正文消息。

    【讨论】:

    • 谢谢你的回答,我没有尝试过你的回复,因为我用其他技术做过这件事,但希望它对其他人有帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-16
    • 2021-11-21
    • 2015-01-15
    • 1970-01-01
    • 1970-01-01
    • 2018-06-15
    • 1970-01-01
    相关资源
    最近更新 更多