File uploading and attachment with Contact Form 7
December 11, 2008
In this post, I will explain the file uploading and attachment feature introduced in Contact Form 7 1.9. If you are not familiar with Contact Form 7, please read the plugin homepage and FAQ first.
Summary
With this feature, you can allow your visitors to upload their files via your form, and then an email with attachments of the files is sent to you.
Please note that this feature uses the API of WordPress 2.7. So, in order to use it, you will need to upgrade your WordPress if you are using WordPress 2.6.x or older.
To set up, two steps are needed: 1) Add file uploading fields in your form, 2) Set up your mail settings to attach the uploaded files. The two steps will be explained in the rest of this post.
Adding file uploading fields in your form
Like other types of form fields, you add a tag code into the Form area in the Contact Form 7 admin panel (Tools > Contact Form 7 in WordPress 2.7).
The tag of file upload feild is like this:
[file your-file]
As with other types of tags, ‘file’ means the type of tag, and ‘your-file’ means the name of the tag.
You can use several options with ‘file’ typed tags. To limit the max file size, use the ‘limit:’ option like this:
[file your-file limit:100000]
The unit of the digits is ‘byte.’ So ‘limit: 100000′ means that the limited max file size is approximately 100 kB.
To limit acceptable file types, use ‘filetypes’ option like this:
[file your-file filetypes:gif|png|jpg|jpeg]
List the file extensions after ‘filetypes,’ and separate them with ‘|’
(pipe) character when you set multiple file types.
You can also generate these tags with the Tag Generator, of course.

Set up file attachments with a mail
For file attachments, the new field File attachments is added in the Mail field set in the Contact Form 7 admin panel. To attach the uploaded files to the mail, put tags into this field as shown below.
File attachments:
[your-file]
As other tags used in the Mail field set, only the name (in this case, ‘your-file’) is needed. Don’t put the tag’s type or options.

If you have multiple files uploaded and want to attach them into an email, simply line them up like this:
File attachments:
[your-file][your-another-file]
(Japanese / 日本語)
Contact Form 7 1.9 にて追加されたファイルアップロードとメール添付のサポートについて説明します。Contact Form 7 自体をご存じない場合はプラグインのホームページおよび FAQ をまずご参照ください。
概要
この機能により、フォームにファイルアップロードの項目を追加して、そこからアップロードされたファイルをメールに添付して送ることが可能になります。
まずご注意いただきたいのは、この機能の使用には WordPress 2.7 の API が必要です。従って、もしいま WordPress 2.6.x 以前をお使いなら、まず先に WordPress をアップグレードしないとこの機能は使えません。
この機能のセットアップは2つのステップに分かれます。1) ファイルアップロード項目をフォームに追加すること、2) アップロードされたファイルを添付して送信するようにメールを設定すること、です。これから順を追って説明します。
ファイルアップロード項目のフォームへの追加
他のタイプのフォーム項目と同様ですが、タグをフォームのテキストエリアに追加することにより行います。フォームのテキストエリアは Contact Form 7 の管理パネル(WordPress 2.7 においてはツール > Contact Form 7 メニュー下)にあります。
ファイルアップロード項目のタグはこんな感じです:
[file your-file]
これも他のタイプのフォーム項目と同様、この場合の ‘file’ はこのタグのタイプを、’your-file’ はこのタグの名前をあらわします。
いくつかのオプションをこの ‘file’ タイプのタグに対して使えます。ファイルサイズの上限を指定したいなら ‘limit:’ オプションを以下のように使います:
[file your-file limit:100000]
数字はバイト単位なので、例えば ‘limit:100000′ とした場合の上限ファイルサイズは約 100 kB になります。
アップロードできるファイルの形式を制限したいなら、’filetypes:’ オプションを使います:
[file your-file filetypes:gif|png|jpg|jpeg]
‘filetypes:’ の後に続けて、アップロード可能なファイルの拡張子を並べます。複数指定する場合は ‘|’ で区切ってください。
もちろん手で入力しなくてもタグジェネレーターを使ってタグを生成することもできます。
メールへのファイル添付の設定
メールへのファイル添付のための項目(「ファイル添付:」)が Contact Form 7 管理パネルのメール項目群に追加されています。アップロードされたファイルをメールに添付するには、この項目に次のようにタグを追加します:
ファイル添付:
[your-file]
メール項目群での他のタグの使用と同様ですが、タグの名前(この場合だと ‘your-file’)だけが必要になります。タグのタイプやオプションを加えないでください。
複数のファイルをアップロードできるようにしていて、それらをまとめてメールに添付したい場合は、単純に複数並べれば可能です:
ファイル添付:
[your-file][your-another-file]



October 28, 2009 at 2:22 am
I am getting the attachments fine. Come to my default email address. Do not think they are stored anywhere but at the default email address. Also have you enabled the types of files allowed? That might help if certain files are not going through.
October 28, 2009 at 6:21 pm
To Contact Form 7 Fan: Your attachment field is wrong. It needs to be [file-622] not [file file-622].
To anyone else. I got my form working except two problems I’m hopping someone can help me with.
When someone leaves a required field blank, I correctly get the yellow box at the bottom saying the form is not filled out. And I get a box with a red border next to the empty field but there is not text in the message box. Just a white box with a red border around it.
Also, and the reason I’m here, I’m not getting an email if there’s an attachment. The form says email was send, I used a small file, but I never get the email. Without an attachment the email shows up just fine. What gives?
October 29, 2009 at 3:55 am
I have this under my setting and it works well.
`[file your-file limit:2000000 filetypes:png|gif|jpg|jpeg|pdf|txt|doc|docx]`
You might also want to try the contact form that comes with the spam filter plugin to test your server settings out.
October 30, 2009 at 11:06 pm
In Opera when I try attach file – the processing image is appearing and nothing happend else. May be this plugin with attachment option not works in Opera?
How to fix it, tell please!
October 31, 2009 at 3:55 am
I have used mainly in Firefox. It could be your browser issue probably, even though more likely it is a server issue.
November 5, 2009 at 7:42 am
I am having a problem where I get the file attachment in the message as encoded in base64. Anyone else have this issue?
November 6, 2009 at 1:57 am
Sorry. Cannot help you out with that issue. Could be an encoding issue on the sender’s side maybe?
November 7, 2009 at 1:01 pm
I just like to add my 2 cents.
The problem was that I could send an email but could not send attachments ( could not upload a file ). I was received the message that the upload had failed.
One comment here, in special, caught my attention:
”
Ed, sure. Maybe you have any idea how to check it?
By the way, for those for whome file upload is working – is this plugin uploading the files to wp-content/uploads/wpcf7_uploads ?
”
I just didn’t realized that the plugin wasn’t using wordpress “default” upload folder ( wp-content/uploads ). Instead, it was a personal folder inside uploads folder.
I already tried something like that and the problem was that the folder created by my script was assigned to the user “nobody” from group “nobody” in the server that host my site.
The problem with that is: I just can’t upload anything to a folder with permissions that doesn’t belong to my user.
In my case, my user is fabio. So my script should create a folder with fabio being the owner ( with permissions xyz).
Contact Form 7 script creates a folder with permissions 733 to the user “nobody”.
The solution: log in your server through the ftp, rename the Contact Form 7 folder (wpcf7_uploads, inside wp-content/uploads ) to anything. Create a folder there ( inside wp-content/uploads ) called wpcf7_uploads and give permissions 733.
That way, your created folder will belongs to your user ( in my case, fabio ). Not to the user “nobody” which is the problem regarding file upload and attachments.
Just to add a bit more information, my html:
Your name (obrigatório)
[text* name]
Your email (obrigatório)
[email* email]
Your file
[file* file filetypes:doc|docx|pdf]
[submit "Send"]
And my Mail settings:
To:
fabio@fabio.com
From:
site@fabio.com
Subject:
fabio test
Attachment:
[file]
Dummy information just to illustrate!
Att,
Fábio Silva.
ps: Great plugin! ^^
November 10, 2009 at 2:21 am
The only folder that I saw was the htaccess folder in my wp-content>wp_cf7uploads folder. Why would the attachments be there if they are sent directly to the email you select to send to?
Thanks.
November 11, 2009 at 4:15 am
Is there any way to attach a file (not uploaded by the form user) to an auto reply email? When someone fills out the form, I want an email being sent back to them along with a .pdf guide. Can this be done? If not, I think it would be a wonderful improvement on an already great product. Thanks.
November 12, 2009 at 2:35 am
It is best to use one of the commercial contact email forms that can send out free books etc. Cannot be done with cf7 presently. Would be great to have though.
November 17, 2009 at 10:36 pm
Hello guys,
Please help me with this.. I have a “Request a catalog” form on my site. Now when a user fills in his/her email address, I want to send him/her an email with the catalog.pdf file attached in this email.
Emailing is working fine but not the file attachment.
I see a File attachments: field in the contact form admin area but am not able to figure out the correct way to use it.
I have this pdf already uploaded to a folder on my server.
Any pointers ??
Thanks a lot,
ak
November 18, 2009 at 4:25 am
Hey Amit. It is not possible to do this with cf7 as far as I know. The cf7 is only used for sending you emails and/or attachments. Do not think it reciprocates back. Would be nice to have that feature though.
November 18, 2009 at 5:43 am
can we not just attach a file using additional headers ?
I used some additional headers(dont remember now which ones) but this made my mail message as an attachment…
specifying a filename on server with the path didn’t worked either…
November 19, 2009 at 4:08 am
I am not following your question. What headers are you referring to? I do not think cf7 is capable of auto reply yet. Will be nice to have it.
November 19, 2009 at 9:41 am
what is the max file size cf7 can take? this is working great for me except I need clients to send me files between 3-6 mb
November 19, 2009 at 5:18 pm
Hi there, i keep having problem “failed to upload file” when i’m testing out the form with file attachment field. May I know how do I solve this?
this is what i put for the Form code:
Attached the order form (required)
[file* order-form limit:512000 filetypes:xls]
and on the mail:
File Attachments:
[order-form]
November 19, 2009 at 5:28 pm
Hi Ed
Basically its not auto responding …
What I have done is.. in cf7’s admin area created a form which takes users-email as input and uses his email address to send him a pre-defined email.
Now all I want is.. along with this pre-defined email content.. also want to send him an attachment..
Any pointers ??
Thanks,
ak
November 19, 2009 at 5:48 pm
Hi there again, when i receive the email, it shows the person’s email address in the “from” field. But my auto-reply doesn’t send back to the same person. May I know why is it so?
November 19, 2009 at 7:50 pm
In case you weren’t aware,
this is not a support forum.
November 20, 2009 at 1:42 am
@Sebastian file limit should be what you specify in the settings. I do not think there is an internal limit in cf7.
November 20, 2009 at 1:43 am
@Levonne why do you have the * in the code? That could be the reason you are getting the error.
November 20, 2009 at 1:45 am
@Amit if you can send me the code I can take a look to see what possibly might be wrong with the code. I have not tried sending auto replies yet.
November 22, 2009 at 7:25 pm
How to add what you say to add : File attachments:
[your-file] ??
Where ? How ?
Thanks !
November 22, 2009 at 10:42 pm
I’m having problems receiving attachments. I’ve followed the instructions above, but for some reason the attachments aren’t showing up in my mail. Could it be because I’m using gmail?
November 24, 2009 at 1:58 am
@serko the email should be fine. A different email address was shown on the training video also. Probably you must have configured the settings wrong.
November 24, 2009 at 2:00 am
@Samuel see this link for the video on installing cf7.
http://www.idiotproofblogging.com/wordpress/contact-form-7-wordpress-install-tutorial.html
Hope that helps.