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
- Sending multipart (text/html) emails via wp_mail() will likely get your domain banned
- getting attachement images src and add classes
- Are captions stored anywhere?
- get_the_post_thumbnail() doesn’t taking style attribute
- 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”
- media_sideload_image file name?
- Mail will not send in HTML
- Give attachments an archive page
- Insert Media – Attachment – Link to : Remove the “attachment page” option
- Retrieving a custom link on an attachment
- Delete attachments from Front end
- get post attachments of a particular size
- How to upload image from front end and save in media library?
- wp_mail recipient array not sending?
- Is there a plugin that allows a user of your site to get an email from you with an attachment?
- Should I use wp_mail or PHP’s mail? [duplicate]
- Insert custom ID into wp_get_attachment_link
- How to add attachment without uploading?
- Reorder “menu order” of attachments to another predefined order
- Prevent Duplicate Attachment When Using wp_insert_post
- Change code to display image attachment page
- Attachment 0×0 size error [closed]
- Add image attachment to post via coding?
- Email ‘from address’ has a www in it
- How To Grab All Type Of Attachments, But Images?
- Removing width and height attributes from wp-get-attachment
- Change filename during upload
- Get post attachment images dimension and use in embed code
- use wp_get_attachment_image() to show attachments
- List Post Attachments – Remove Image Thumbnails
- Send email button in custom post type backend
- delete image attachments of a custom post type except featured image
- Display attachment resolution size
- Import Attachments – not attaching to post_parent
- Where does the gallery shortcode gets its attachments from?
- media ‘path’ issue / concern when bringing files live
- Is it possible to share media files between multiple WordPress sites?
- How can I attach Facebook Open Graph data to an Attachment Page?
- Set Attachment Image File URL as GUID
- How to update the title of audio file through its attachment metadata
- Delete associated thumbnails when calling wp_delete_attachment
- Proper use of wp_get_attachment_image?
- Get title of post image is attached to
- Help with filter for wp_notify_moderator()
- Correct attachment size
- Gutenberg Block: Image resolution
- Pass return-path additional parameter in wp_mail
- Looking to limit file attachment downloads
- 500 internal error at wp_generate_attachment_metadata
- How can I return multiple image attachments with wp_get_attachment_image_src
- How to let a role handle media without post permissions
- Will wp_get_attachment_metadata display PDF metadata (eg: keyword, author, description)?
- How do I get just the title from wp_get_attachment_image
- i want attachment.php to return the image
- List all files from subpages
- Add videos/images preview to bbPress attachment
- Using wp_mail to send email?
- Updated : how to make email optional while user registration using default wordpress form
- Change attached img anchor link to post link
- How can I remove the product short description from the WooCommerce Mails?
- How to view exact image dimensions of a media in Admin view?
- Custom user registration fields in user_register hook
- wp_get_attachment_image_src calling wrong location
- wp_delete_attachment doesn’t delete image files / doesn’t work
- Get attachment URL from attachment Link in WordPress
- How to open an attachment based on the date picker
- Multisite – SMTP not working on other network sites
- How to use previous/next image link, ignoring parent posts/attachments?
- Using $_FILES variable into the same function for uploading images and files
- Wp_mail doesnt work
- WP media attachment location vs permalink
- Removing delete permanently button in uploading files media
- Remove attached media
- Incomplete attachment page
- How to retrieve “custom url” from image attachment in wordpress
- list of attachments: wp_get_attachment_link works, wp_get_attachment_image does not
- Custom attachment field dissapearing
- How can I let users access a specific attachment?
- What is the most efficient way to retrieve a group of image URL’s from different attachment ID’s of a specific crop size?
- How to wrap this Link with an Image?
- How to save media-form on custom tab
- I want to edit documents on my blog without the need to download and upload files again [closed]
- Open attachments in new tab/window
- One audio attachment, with two possible interchangeable extensions