## Export Form Data to a CSV then send it as an attachment – contact form 7

Question

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

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);

}

0
2 years 2020-08-12T01:10:44-05:00 0 Answers 50 views 0