Categories
WordPress Plugins WordPress Tips

File uploading and attachment with Contact Form 7

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.

Tag generator for file

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.

file attachment to mail

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]

154 replies on “File uploading and attachment with Contact Form 7”

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.

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?

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.

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!

I am having a problem where I get the file attachment in the message as encoded in base64. Anyone else have this issue?

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! ^^

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.

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.

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.

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

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.

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…

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.

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]

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

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?

@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.

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?

@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.

Love the plug-in… I’ve been having one issue, though. All types of files seem to be attachable, but I can’t get Excel files (xls and xlsx) to attach at all. They always return an error. I’ve tried specifying that they’re OK with no luck.

Any idea…?

Hi,

I just put contact form 7 into my website. Everything seems to work fine. Thanks a lot for this great product! I have just one question. I would like to have instead of button at which is written “Browse” translation in my language. Is it possible?
I am already using “Serbian”, but that button-name has not been translated.
Thanks!

@Vladimir. That could be because it is only a button with an image on it. You can change the image to whatever language you wish it to be and upload it to your CSS file.

I get the email but only with the name of the attachment, the physical attachment never makes it. I FTP’d the site and in the folder “wp-content/uploads/wpcf7_uploads” I see a .htaccess file with a line of code that reads “Deny from All”, how can I make it so I receive the attachment.

This is the code I’m using in the form:
[file your-file limit:1mb]

In the mail body:
[your-file]

Many Thanks!

@Jack make the changes in the .htaccess file so you can receive attachments too. SOme hosts will block them regardless on that file or command.

@Ed What changes to the .htaccess file are you recommending? Which .htaccess file is this? Where is it located?

Thanks.

How can I disable file deleting in the server?

I want the users to be able to upload files, up to 100MB but offcourse that kind of file can’t be recieved via e-mail.

How can I keep a copy in the server and recieve a link to the file instead or something like that?

Thanks!

Is there a way to save uploaded files to a folder on the server? If so, how can I save files in a “/username/” folder if the user is logged in? all public files would go in separate folder..

Hi how can i turn off the attachment supported file types? i mean simply turn off the extension validation for uploading files

I get the email and also get attachment file but in the folder “wp-content/uploads/wpcf7_uploads” I see a .htaccess file with a line of code that reads “Deny from All”, when i rename with htaccess.txt and try to fill the contact form and upload the file then it again renamed to .htaccess and there is no any upload file how can I make it so I receive the attachment.

There are also a few other things to try if you’re still having issues:
1. Make sure upload via HTTP is allowed in php.ini
2. If you’re trying to do attachments greater than 2MB, you may need to change your settings in php.ini – 2MB is the largest size allowed by default.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s