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, $headers);
foreach($records as $record) {
fputcsv($fd, $record);
}
rewind($fd);
fclose($fd);
return $filepath;
}
will solve your problem. See http://codex.wordpress.org/Function_Reference/wp_mail
Related Posts:
- wp_mail not sending attachment
- Attach pdf from dynamic url
- Attach a external file as attachement using wp_mail
- wp_mail attachment not working in wordpress
- Adding attachment file name to email link
- How to allow specific extensions and file size to wp_mail attachment?
- Post Via Email – How to send Attachments with it (e.g. PDF File or JPEG Image)?
- Email Attachment from Form Submit
- Auto create file and send it via wp_mail()
- Could not get attachment using wp_mail
- wp_mail Allow Remote Attachments from CDN
- Send data URL string as an attachment in wp_email
- wp_mail doen’t send mails whit attachment
- Using wp_mail to send attachment from a file stream content
- wp_mail doen’t send mails with attachment
- Sending multipart (text/html) emails via wp_mail() will likely get your domain banned
- How To Retrieve An Image Attachment’s Alt Text?
- Why won’t wp_mail() let me set the From: header when plain old PHP mail() will?
- How to manage attachment relationships for specific posts in WP 3.5+
- How to set SMTP programmatically
- Can I add a Category Metabox to attachment?
- Change attachment filename
- How to get attachment file name not attachment URL
- WordPress refuses to send mail, “…your host may have disabled the mail() function”
- How to trigger a refresh in the media modal
- Do something after sending email
- How to add headers to outgoing email?
- Get all post attachments except featured image
- Programmatically adding images to the media library with wp_generate_attachment_metadata randomly fails
- getting attachement images src and add classes
- How can I bulk delete media and attachments using WP-CLI?
- Getting a taxonomy’s thumbnail url
- Check if post has attachments (not image)
- How to cleanly delete attachment but retain original file?
- Changing attachment urls?
- Add custom class to attachment in media library grid mode
- wp_mail and BCC headers
- Are captions stored anywhere?
- Trying to hide buttons from Attachment window
- get_the_post_thumbnail() doesn’t taking style attribute
- How do I override the Message-ID header of wp_mail function?
- Expanding new Media Uploader in WordPress 3.5
- How can I UN-attach media from a post?
- Uploading Multiple Attachments From Front-End With A Description
- Validate alt text for attachments?
- complex restriction of items in media library
- Remove duplicate attachments
- Edit image / Delete image link
- How could I add button next to “edit image” button in “Attachment Details”
- Applying automatic link class to images embedded to posts
- wp_mail script with jQuery post
- How to get attachment caption (get_the_excerpt gives parent post excerpt) ?
- Is it possible to query specific WordPress Attachment files (.ppt & .pdf) and output them in a list?
- wp_mail – Remove sitename from email subject
- media_sideload_image file name?
- Get all posts (of any post type) an attachment is used in
- Detect if is image unattached
- How to single click to download image in single post
- delete attachment from front end
- Mail will not send in HTML
- Unattaching unlinked images
- How to get attachments for a specific post type?
- Give attachments an archive page
- Include HTML template file in wp_mail
- Email sent from WordPress has HTML tags
- Reset Password – change from name and email address
- custom fields for attachments?
- Insert Media – Attachment – Link to : Remove the “attachment page” option
- Show Post ID in “Find Posts or Pages” box in Media Library?
- URL rewrite with add_rewrite_rule and attachment_id
- How to add media from front-end to an existing post?
- How to set author for post AND post attachments
- Can I attach a document (eg: PDF) but have a JPEG as a thumbnail?
- Retrieving a custom link on an attachment
- Get attachment from post
- How can I display custom fields value from attachment media?
- Delete attachments from Front end
- Add column for attachment file size
- Creating a multi-file upload form on the front end for attachments
- how to test for attached image
- Unable to upload specific .zip file type via frontend in WordPress 4.0
- Get attachments (get_posts) and WP 3.5 new uploader
- get post attachments of a particular size
- Change image link: wp_get_attachment_link
- Multi-line captions on attachments
- Make individual attachments private?
- exposing attachment uploading to the front end — delicate
- Gel all image from certain post type
- Making images from single.php pointing to an attachment .php template
- Add_Filter example for wp_get_attachment_link
- Few chars getting replaced with ‘=’ in mail content in wp_mail()
- File upload from front-end form (as attachment) not working
- Change the Permalink for wordpress attachment
- How to upload image from front end and save in media library?
- Can i hide the attachments from media which I uploaded from front end?
- ID of images from gallery
- Get the attachment URL on single.php
- wp_mail recipient array not sending?
- How to get list of paths (not urls) for an image
- wp_mail not recognizing cc and bcc headers