How to create a CSV on the fly and send as an attachment using wp_mail?
That’s because wp_mail expects the attachment to be a filename (filepath) that it can attach and send. You are supplying a string containing the contents of the file: function create_csv() { $filepath=”/path/to/the/file.csv”; $fd = fopen($filepath, ‘w’); if($fd === FALSE) { die(‘Failed to open temporary file’); } $records = array( array(‘dummy’, ‘data’, ‘found’, ‘here’) ); fputcsv($fd, … Read more