Is file attachment working on your site?

Hi, if you are using Contact Form 7 plugin and its file uploading and attachment feature, could you help me solve a problem?

Since I released Contact Form 7 1.9 with the feature, I’ve received some trouble reports that says file uploading isn’t working on their site. However, when I tested it on my site and it worked correctly. I think some kind of condition of their server environment could cause such troubles, but I have no clue to detect the condition for now.

So, if you have some time, please answer surveys below.

And also, please write a comment to this post about the detailed information of your environment. What version of WordPress and Contact Form 7 are you using? What tag did you enter into the form field and the mail attachment field? Are you using hosting service? If so, which one are you using? (e.g. Blue Host, DreamHost and like those) Any information would be much appreciated.


Comments

99 responses to “Is file attachment working on your site?”

  1. I am using Dreamhost with WordPress 2.7

  2. Hi Miyoshi :-)

    This is my environment :

    Contact Form 7 plugin 1.9.2

    Hosting: MediaTemple + PHP5

    WordPress 2.7

    File attachments: [file file-439]

    wpcf7_uploads chmod777 (the directory is empty) -> maybe the problem ?
    wpcf7_captcha chmod777 (i see files on the diretory) -> captcha works

    The mail is correctly send and i receive it but without attachment.

    Thx for your help and your nice plugin !

    K.

  3. Hi.

    Here is my informations:

    WordPress 2.7
    Hosting: HostStar (PHP 5)
    Plugin: Contact Form 7 1.9.2
    File Upload tag: [file file-attachment]

    The file upload doesn’t work for me. I don’t receive an email when I load a file in the file upload.

    Everything else works fine.

  4. hi

    I receive an mail but without attachment.

    When I comment two lines (in function mail):
    if (version_compare($wp_version, ‘2.7-beta1’, ‘<‘)) // wp_mail() file uploading option isn’t suppoted
    $files = array();

    i receive mail with attachment.

    SlawekG

  5. @Kuban and @deniz thanks for the info. I suppose you’ve set tags for file attachment in the file attachment field as the post says. Please let me confirm that those are correctly [file-439] for Kuban and [file-attachment] for deniz respectively.

  6. @slawekg, I checked your site and found that the ‘generator’ meta tag in the header shows:

    <meta name="generator" content="WordPress abc" />

    This was the cause of the issue, at least for your case.

    I have no idea what this “WordPress abc” is. Where is it from? Do you have any idea? I’ve seen the same thing on another WordPress blog, and found a thread on the support forum which is written about it 6 months ago.

    This is really weird! What’s the “WordPress abc” ?! Messages from aliens? Please inform me if someone knows this.

  7. I’ve installed plugin “WP Security Scan”. On plugin’s main page:
    “WordPress version: 2.7 You have the latest stable version of WordPress.
    Your table prefix is not wp_.
    Your WordPress version is successfully hidden.
    WordPress DB Errors turned off.
    WP ID META tag removed form WordPress core”

    In my opinion the line “Your WordPress version is successfully hidden.” is source of “WordPress abc” problem.

    SlawekG

  8. I found aliens :)

    This file:
    wp-content/plugins/wp-security-scan/functions.php

    contain line:
    $wp_version = ‘abc’;

    SlawekG

  9. I was having problems that went away after deacting the wp security scanner from donncha

  10. slawekg, thanks for the info.

    $wp_version = ‘abc’;

    Oh no! It’s wrong approach, as $wp_version is an important variable which is not just used for meta in header.

  11. WordPress has a filter for the ‘generator meta’ line. See Trac. IMHO those ‘security’ plugins should use this filter instead of overwriting $wp_version directly.

  12. I really like your script. I use Google Analytics. If I would like to track who is sending me emails, how can I do that? Thank you!

  13. This plugin is great – thanks for this.

  14. Isak, currently it has no function for Google Analytics. I have no idea how to track such data.

  15. Upon first installing I had trouble getting it to work, but I was able to fix it and it now works very smoothly. Feel free to email me if you have questions.

  16. If I made the field for file uploading a most like [file* foto filetypes:gif|png|jpg|jpeg] I reciev the message (please file out the upload field).

    So it dosent work :(

    please excus my bath English !

  17. Rene, you also need to insert a tag in file attachment field in the Mail area. Please read this first if you have not read yet.

  18. I’ve got it. you need to add the tag [you-file] in the “message body” box to have the attachment send.

  19. I have use this settings:

    At Form: [file* foto filetypes:gif|png|jpg|jpeg]
    At Mail under File Attachments: [file foto]
    Mail 2: not used.

    Buth still it dosent work.
    If i upload a file en click send, the message:
    I dont uploaded a file ?

  20. Rene, use [foto] instead of [file foto].

  21. I have read the doc at your site, and I have use [foto] ore [file foto] buth still I dont get it.

    Whene I change [file* to [file there is no file at the email, so I think if use * I dont have to read everytime the email.

  22. Same like Rene ! :(

  23. Contact Form 7 plugin 1.9.2
    Wordpress 2.7
    Hosting: inmotionhosting.com

    I can’t get file attachments to work either. They show up in the uploads directory temporarily, then disappear (which is expected), but they never get attached to the email. I used the correct tag [resume] in the file attachments box, but no luck.

    Also, having the file upload field required doesn’t work, it always gives an error telling me to fill in the required fields.

  24. Please make sure that the name in the file ‘uploading’ tag and the one of the file ‘attachment’ tag is matching. For example, when you use [file abc] as file uploading tag, you must use [abc] as file attachment tag. If they don’t match, nothing will be attached. If you don’t know the basic usage of Contact Form 7, please read this and FAQ first. And, there is ‘File attachment’ input field and you must insert file attachment tag into it, not into the message body textarea.

  25. Please excus, buth if you read the above message, I use all the settings that are writen in the doc of your site.

    The contact form is great all things are working buth only the file dosent work.

    Now you can write every time: [file abc] ore [file cba] and [abc ore [cba] at the attachment, buth still it dosent work.

  26. As I wrote in this post, I have no clue for this, even if problems really exist. So I want information.

    I wonder why 60% many users say “Not working”, while rest 40% answer “Working”. I almost give up. Someone, help me, please.

  27. I have now write [file file] in to the form editor and [file] under “file attachments” and it works now!

  28. Thanks Deniz !

    I got [file foto] at the form editor, and at the attachment only [foto] and its working fine.

    Buth the required field like [file* foto] ore [file foto*] dosent work ?

  29. No Problem Rene.

    I have the same problem when I make a * to the tag. But I do not need a required file upload :P

  30. Well, I figured out what was wrong with required file attachments..

    around line 171 in wp-contact-form-7.php
    […
    $file = $_FILES[$name];
    if (empty($file) && ‘file*’ == $fe[‘type’]) {
    $valid = false;
    ..]

    The problem is $file will NEVER be empty, because even if you don’t have an uploaded file, the last two points in the $file array will have an error code and a file size. It’s better to check the $file[‘name’] for being empty.

    $file = $_FILES[$name];
    if (empty($file[‘name’]) && ‘file*’ == $fe[‘type’]) {
    $valid = false;

    I’ve messed around with the attachment thing, but still can’t get that figured out…

  31. Yes, it works! Thank you for this, sir.

    Environment:

    Contact Form 7 plugin 1.9.2.1

    Hosting: HostGator + PHP5

    WordPress 2.7

    File attachments: [file* file-upload-09 filetypes:jpg|jpeg|gif|png|zip] (also worked as NOT required: [file file-upload-09 filetypes:jpg|jpeg|gif|png|zip] )

    wpcf7_uploads chmod777 (the directory is empty)

  32. It seems the correct header Content-Type isn’t supplied…that’s the problem I encountered anyways.

    In function compose_and_send_mail
    […
    $mail_headers=”From: $mail_sender\n”;
    if ($mail_template[‘use_html’])
    $mail_headers .= “Content-Type: text/html\n”;
    …]

    The problem is if an attachment is present, you need to change the content type to multipart/mixed, otherwise the email server won’t know you have an attachment. I’m guessing the reason why it got through for some people is that their email server doesn’t care much about headers, and just accepts the email anyways. It’s also probably a good idea to have the header defaulted to plain/text if there isn’t an attachment, and if you didn’t specify text/html.

    In the end, I got it working for me by replacing the above code with this:
    […
    if ($mail_template[‘use_html’]){
    $mail_headers .= “From: $mail_sender\nContent-Type: text/html\n”;
    } elseif ($attachments){
    $mail_headers .= “From: $mail_sender\nContent-Type: multipart/mixed\n”;
    } else {
    $mail_headers .= “From: $mail_sender\nContent-Type: text/plain\n”;
    }
    …]

    I hope this helps other people who are having problems.

  33. Austin, thanks a lot. I’ll update the plugin and release it shortly.

  34. My tag: [file music-file limit:10485760 filetypes:wav|mp3|m4a]

    In “File attachments” field: [music-file]

    Contact Form 7 v. 1.9.2.2

    I use BlueHost.

    I receive no errors; the file appears to upload but when I receive the email there is no attachment!

  35. Hi

    The file upload only works for files smaller than about 1.6mb

    I’ve tried changing my php.ini file to set file uploads much much higher.

    I’ve also tried using larger file limits in the form tags themselves with no success.

    Aside from this, I love this plugin and will be making regular donations to help keep it going.

  36. Ok, I’ve narrowed down the problem – the problem is not with the file upload script itself. The files successfully upload to the wpcf7_uploads folder regardless of how big they are.

    The problem is when you attempt to attach these files to the email. If the file size is greater than 1.5mb – the file gets uploaded ok but the email doesn’t get sent. Furthermore, the form doesn’t display any kind of success or failure message and the rotating arrow gif just sits there rotating forever.

    It seems that the email script isn’t handling attachments larger than 1.5mb

    I’d be incredibly grateful for a solution to this

  37. I know it’s not much but I’d be happy to PayPal a couple of hundred dollars for a solution to this! :)

  38. file attachment works only for one file. I would like to attach two separate files.

    using godaddy linux hosting and wordpress 2.7.1

  39. Yes, I am having that problem. I cannot upgrade to the new version because when I try to upload the files to WP 2.7 on a Mac using Firefox.

    When I try to add a new plugin it says that it does not recognize it as a plugin (contact-form-7.1.9.2.2.zip)

  40. Hi all!

    i am having one problem, i have one form with file attachment, the e-mail comes with success!

    but the body of the message that was with html code, it comes as pure text …

    the option “Use HTML content type” is checked, but the email comes with “Content-Type: text/plain; charset = “UTF-8″”

    can help my?

    thankz a lot for plugin!

  41. It doesn’t work for me. I host with bluedomino

    WP 2.7.1
    [file* file-663 filetypes:pdf|txt|doc|zip]

    The email is sent ..but there is no attachment.

  42. Hey there,

    First off, awesome plugin. Thank you so much!

    Second,
    My only problem at this moment is the file upload part – I get the emails just fine, it says sent successfully – this is ofcourse after I disabled Bad Behavior – but I get no attachment!

    Stats:

    Domatic for hosting
    Wordpress 2.7.1
    Comment Form 7 – 1.9.2.2

    [file file-406 limit:10485760 filetypes:jpeg|jpg|gif|png|pdf|eps|doc|txt]

    Bad Behavior disabled
    Akismet enabled

    Any ideas? Is there a limit I am not aware of? Inbox is currently 200 MB and as you can see the limit I set is about 10 MB
    I also did the [your-file] part too.

    Everything works but the file upload part is crucial I guess.

    Thanks a million!

  43. Hi Miyoshi,

    I was having a terrible time with a plugin that lets users upload photos, and resizes them and moves them around. It turned out to be that people with non-standard folder structures (where the blog wasn’t in the root directory or the wp-content or uploads was a little different…all legal stuff, but not standard). One of my users helped solve it by using the WP_CONTENT_DIR and WP_CONTENT_URL globals to get to the right file locations.

    Email if you’d like to take a look at the code, you can download it from WP….I’ll send you the link if you want.

    I feel your pain over this. It took me about 10 days to fix my problem and it plagued me to no end.

    Cheers,
    Byron

  44. cannot attached file.
    pleasee help..

  45. ryanrushing Avatar
    ryanrushing

    Hostmonster for hosting.
    Wordpress 2.7.0
    Contact Form 7

    [file file-806 limit:4194304]

    File upload doesn’t work. When I send the email, all I get is the text from the message.

  46. If option “Store uploads in this folder” to change then file upload will not work.

    Solution:

    around line 44 in wp-contact-form-7.php
    […
    if (! defined(‘WPCF7_CAPTCHA_TMP_DIR’))
    define(‘WPCF7_CAPTCHA_TMP_DIR’, WP_CONTENT_DIR . ‘/uploads/wpcf7_captcha’);
    if (! defined(‘WPCF7_CAPTCHA_TMP_URL’))
    define(‘WPCF7_CAPTCHA_TMP_URL’, WP_CONTENT_URL . ‘/uploads/wpcf7_captcha’);

    if (! defined(‘WPCF7_UPLOADS_TMP_DIR’))
    define(‘WPCF7_UPLOADS_TMP_DIR’, WP_CONTENT_DIR . ‘/uploads/wpcf7_uploads’);
    ..]

    need to replace on
    [..
    if (! defined(‘WP_UPLOAD_DIR’) || ! defined(‘WP_UPLOAD_URL’)) {
    $path = str_replace(ABSPATH, ”, trim(get_option(‘upload_path’)));
    $dir = ABSPATH . $path;
    $url = trailingslashit(get_option(‘siteurl’)) . $path;
    if ( $dir == ABSPATH ) { //the option was empty
    $dir = ABSPATH . ‘wp-content/uploads’;
    }
    if (! defined(‘WP_UPLOAD_DIR’))
    define(‘WP_UPLOAD_DIR’, $dir);
    if (! defined(‘WP_UPLOAD_URL’))
    define(‘WP_UPLOAD_URL’, $url);
    }

    if (! defined(‘WPCF7_CAPTCHA_TMP_DIR’))
    define(‘WPCF7_CAPTCHA_TMP_DIR’, WP_UPLOAD_DIR . ‘/wpcf7_captcha’);
    if (! defined(‘WPCF7_CAPTCHA_TMP_URL’))
    define(‘WPCF7_CAPTCHA_TMP_URL’, WP_UPLOAD_URL . ‘/wpcf7_captcha’);

    if (! defined(‘WPCF7_UPLOADS_TMP_DIR’))
    define(‘WPCF7_UPLOADS_TMP_DIR’, WP_UPLOAD_DIR . ‘/wpcf7_uploads’);
    ..]

  47. For what it’s worth, I think the 40% who say it isn’t working, are likely making mistakes, due to somewhat lacking/unclear instructions. I am a pretty adept wordpresser, and plugin guy, and I was only able to get this fully working after I spent a lot of time futzing based on the comments. I’d suggest a more robust set of documentation with more clearer instructions on how to get this working with the file attachments. The plugin is great, but clearly from the comments and poll, and despite the fact that the plugin DOES work, the problem is in that people aren’t setting it up properly. I’d bet a million that better documentation would solve all of this.

    Thanks for a solid plugin!

  48. Yeah Andrew, I agree… documentation.

    IF YOUR ATTACHMENTS AREN’T WORKING… make sure you put

    [upload]

    in the file attachments field under the Mail section.

  49. So how to I get this working?

  50. Jamil Walker Avatar
    Jamil Walker

    It worked for me.

    wp 2.7.1
    cf 1.9.3
    akismet enabled

    Didn’t make any modifications to the files.

    I added the attachment like any other field.
    example: [whatever-name-you-used].

    At first I didn’t think it worked because messages without attachments went to my inbox. But I realized it was sent to spam folder.

Leave a comment