I want to export the form data and send it as an attachment. In this case, can i rewrite the file (/uploads/2020/08/sample.csv) with the form data and send it as an attachment.
right now, it is just a blank attachment when i receive it in my email
Here is my code in function.php, Please help me:
add_action( 'wpcf7_before_send_mail', 'add_form_as_attachment', 10, 1 );
function add_form_as_attachment(&$WPCF7_ContactForm) {
$contact_form = WPCF7_ContactForm::get_current();
$Fname = $formdata['firstName'];
$Lname = $formdata['lastName'];
$email = $formdata['email'];
$list = array (
array( 'First Name:',$Fname),
array( 'Last Name:', $Lname),
array( 'Email:', $email),
);
$fp = fopen( site_url() . 'uploads/2020/08/sample.csv', 'w');
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
}