【问题标题】:Send custom variable in Email - contact form 7在电子邮件中发送自定义变量 - 联系表格 7
【发布时间】:2019-05-28 23:15:18
【问题描述】:

| add_action('wpcf7_before_send_mail', 'save_application_form'); 函数 save_application_form($wpcf7) {

        if ($wpcf7->id == 19) {

          $client->setAccessToken($_SESSION['accessToken']);
            $service = new Google_DriveService($client);
            $finfo = finfo_open(FILEINFO_MIME_TYPE);
            $file = new Google_DriveFile();

                  $wpcf7 = WPCF7_ContactForm :: get_current() ;
            $form_to_DB = WPCF7_Submission::get_instance();
            if ($form_to_DB) {

                /* @var $mail type */

                $uploaded_files = $form_to_DB->uploaded_files(); // this allows you access to the upload file in the temp location
                  $fileId = '';
            $cf7_file_field_name = 'file-181'; // [file uploadyourfile]
            //Do the magic the same as the refer link above
            $image_location = $uploaded_files[$cf7_file_field_name];
            $mime_type = finfo_file($finfo, $image_location);
            $file->setMimeType($mime_type);
            $test = pathinfo($image_location);

            $service->files->insert(
                    $file, array(
                'data' => file_get_contents($image_location),
                'mimeType' => $mime_type
                    )
            );
            $filetest = $service->files->get($fileId);
            $add = $filetest['items'];
            $final = $add[0]['alternateLink'];
            // the message
            $mail = "Link:" . $final;


       $mail = $wpcf7->prop('mail') ;

        $wpcf7->set_properties( array("mail" => $mail)) ;


                        // return current cf7 instance
                        return $wpcf7 ;
            }


        }

    }

|我在该函数中有一个函数我有一个变量用于存储共享链接。我想将此变量传递给联系表格 7 邮件

【问题讨论】:

  • 您想将自定义变量值发送到电子邮件中?
  • 你得到变量值了吗?
  • 是的,我想在邮件中发送自定义变量
  • 是的,我得到了变量值。
  • @P.patel 问题解决了吗?

标签: wordpress contact-form-7


【解决方案1】:

请检查以下代码以了解您的问题。

            add_action( 'wpcf7_before_send_mail', 'my_add_custom_field' ); // its called befoee email sent
            function my_change_subject_mail($WPCF7_ContactForm)
            {
                $wpcf7 = WPCF7_ContactForm :: get_current() ;
                $submission = WPCF7_Submission :: get_instance() ;
                if ($submission)
                {
                    $posted_data = $submission->get_posted_data() ;
                    // nothing's here... do nothing...
                    if ( empty ($posted_data))
                    return ;

                   $mail = $WPCF7_ContactForm->prop('mail') ;
                   // Your code
                   if ($WPCF7_ContactForm->id == 19) 
                   {
                        $filetest = $service->files->get($fileId);
                        $add = $filetest['items'];
                        $final = $add[0]['alternateLink'];
                        $mail . = "Link:" . $final;
                   }
                    // Save the email body
                    $WPCF7_ContactForm->set_properties( array("mail" => $mail)) ;

                    // return current cf7 instance
                    return $WPCF7_ContactForm ;
                }
            }

您只犯了一个错误,没有保存邮件正文。

【讨论】:

  • $WPCF7_ContactForm->set_properties(array("mail" => $mail)) ;返回 $WPCF7_ContactForm ;我必须放在两行以上对吗?
  • 正确检查我的代码,如果你只放了那你就没有合并原始电子邮件,所以复制粘贴我的整个功能它会帮助你
  • 邮件已发送但变量不在邮件中。什么都没找到
  • 如果你查看我之前的评论,我问过Do you get variable value?,你说是的。
  • 然后从您想要附加字段的位置编辑您的问题?
猜你喜欢
  • 2012-07-05
  • 1970-01-01
  • 2017-04-22
  • 1970-01-01
  • 2011-03-29
  • 1970-01-01
  • 2013-10-07
  • 1970-01-01
  • 2021-07-29
相关资源
最近更新 更多