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”

Wow, that’s really great news! I’ve been waiting for the file upload feature ^^ I’ll give it a try and will send you an updated translation file ASAP. Thank you!

I love this contact form. The only thing lacking is a way to add a drop down list or other means for having selectable recipients in a form. Like if I wanted a email “x” form, where people could choose someone to contact.

this is a fantastic plugin, thank you very much.

the file upload feature is exactly what i gave been waiting for. but…. my form only works if i don’t choose a file to upload, if i do choose one the arrow just sits spinning and nothing happens when i submit the form.

i’m using wp2.7, and trying to upload a 10kb word doc, my tag looks like this:

[file attachment limit:250000 filetypes:pdf|doc|docx]

how can i go about finding out what’s causing the problem?

many thanks
simon

I just installed your plugin and it’s working fine, except I can’t seem to make the radio buttons or selection boxes work as they should. The show up my page as they should. However, when I receive the email, the selections made are not included in the email. What am i don wrong?

Also, how do I change the size of fields or text boxes?

Thanks,
Gustavo

lukeamarsh, check your wp-content/uploads directory. There should be wpcf7_uploads directory under it and it should be writable. Contact Form 7 automatically creates it, and then uploaded images are temporary copied into the directory. If you don’t see it, manually creating it might help.

hello again,

i install the new wordpress 2.7 but don t work the attachment, i create the directory with 777, i setup all thinks but nithing, when i submit the message with a photo the message is ok, i don t receive any error :( what is wrong

sorin, which version of WordPress and which version of Contact Form 7 are you using? How did you set up in detail? Have you read the content on this page?

miyoshi, thanks alot for your plugin, it’s really helpfull. ;)

I am sorry this time I could not be able to donote your plugin, may be if I have much money!
heh..he..he.!

Kind Regards,

I set up the forms and they work and submit just fine, but when i attach a file, i cannot see it and i have checked the upload folder and i still cannot find it. any help please??

if i did it right, here i will upload a photo of it, there is a link to the image so you can see for yourself

hey hun :) nevermind, i realized it was my mail server that was working against it. all is well. Cheers :)

This is one of the best plugins! I have everything working except that I don’t receive the attachment in the email that I am sent. The attachment looks like it uploads in the form, but when I receive the email, there is no attachment with it.

Any help is gratefully appreciated!

Thanks

@jonluciano, have you inserted a correct tag into the File attachments field?

Some other users reported that they had issues like yours, some of them said their server setting was bad and it was the cause. I don’t know in detail.

Sending attachment not work with Worpress 2.7

The form is setup and work perfectly.
Upload directory is ok on the server, chmod 777
I add the tag of upload field to the mail

but nada, no receiving attachment and no error message ???

could you fix it ?

thx :-)

Hi, I was wondering if it is possible to show the user’s uploaded image on the screen for them to preview and approve before the email is sent? Thought there might be a way to include this since the image is already temporarily copied to the server before being emailed, but maybe a way for this copying to the server to happen before hitting the final submit button?

I need help. Contact form doesn’t accept yahoo or gmail. if sender email address is gmail or yahoo it gives orange error “Failed to send your message. Please try later or contact administrator by other way.”

Can you help me out

はじめまして。
すばらしいプラグインなので是非使わせて頂きたいのですが、万策尽きましたので質問させて頂きます。
当方の試した手順を説明すると長いため、箇条書きにて失礼致します。

1/画像添付送信をテスト。一度成功のメッセージが表示された(画像名:t_banner.gif)
2/メールが届いたが、画像が添付されていなかった
3/wp-content/uploads/wpcf7_uploadsの内容を確認しに行ったが、No such file or directoryというエラーが出ており、フォルダ内を確認できず、また、フォルダ自体を消すこともできなくなる
4/del.cgiにてuploadsを消去
5/再度uploads/wpcf7_uploadsを設置、書き込み権限を設定し、画像添付送信を試みるが、何度やっても「ファイルのアップロードに失敗しました。&入力内容に不備があります。確認してもう一度送信してください。」と出てしまう

※画像添付なしではきちんと送信できます

コンタクトフォームの設定自体は、何度も見直しているので
間違いがないはずなのですが…
できれば、諦めずにこのまま使えるようにしたいと思っておりますが、現状途方に暮れております。
どなたかお分かりになる方がいらっしゃいましたら、お教えいただければ幸いです。
何卒宜しくお願い申し上げます。

kome さん、状況から見て間違いなく wpcf7_uploads フォルダかその親フォルダのパーミッション設定が正しくないことが原因です。もう一度よく確認してみてください。

このコンタクトフォームに限らず WordPress の通常のメディアアップロードもできていないんではないかと推察しますが、どうでしょうか?

miyoshi様、ご返答どうもありがとうございます。
私もパーミッションが原因かと思い、いっそ親フォルダも含め777にしてみたのですが、これがまずいのでしょうか?
WordPressのメディアアップロードは正常に出来ている状態です。(wp-content内に画像がアップロードされています)

度々になり申し訳ございません。
wp-content、uploads、wpcf7_uploadsのパーミッションをすべて707にしたら解決しました!
大変ご迷惑をおかけ致しました。

I am using your contact form on my girlfriend’s website and I think it works perfectly except for one issue. I have been searching all your coding, but cannot locate the problem. When attaching a image or the source becomes:
Content-Type: application/octet-stream
instead of:
Content-Type: image/jpeg

Maybe it is out of my server, but I have the feeling it is the coding from the plug-in. Not a huge deal but a small annoyance to have to open another application to see the images being sent to me when using Mozilla Thunderbird 2.0, Safari and Outlook work fine for some reason even though they shouldn’t.

Hello, It’s very interesting to use your plugin. Two thumbs for you! ;)

But, why i can’t upload MP3 files? I make this config:

[file MP3 limit:10000000 filetypes:mp3]

Works great !

Follow these steps:
[file file-26 limit:100000000] add options for files

set ../wp-content/uploads to 777
set ../uploads/wpcf7_captcha to 777
set ../uploads/wpcf7_uploads to 777

Congratuations

I found a huge problem. The reason my attachment is not being sent with an email is because I have Mailpress plugin on my WordPress setup. IT IS CONFLICTING with the Contact Form 7! I deactivated my Mailpress plugin and the attachment sent just fine. What can be done about this and get resolved? Mailpress is STOPPING attachments from being sent and delivered to email!

Is it possible for the uploaded file to remain on the server and potentially not be sent via email?

It seems that when I upload the file remains in the wpcf7_uploads directory momentarily but is deleted as the message is sent.

hey all!

I had the same issues with the file att. not showing up…

what I did to solve it was similar to münir aksu above…

I simply RE-ADDED the File upload option. If you do this, you get a new code, mine was: [file file-792](I didnt rename it)

Then in the email section, I put:
[file-792]

And voila! it worked.

I would like the contactform to be used in a reverse way. That means that when a guest leaves his name and e-mailadres, he will automaticly get a mail from me with an attachment. Everything works, except for the last.

Can I upload a file which I can attach to the mail?

This is what I do:

Upload your picture here (100kb maximum)(required)
[file file-db limit:100000 filetypes:jpg|gif]

I added to File attachments:
[file-db]

I rewrite permission to:
wpcf7_uploads>> 777

Everything is set right?

I go to my website and see the form is nice.

I tested and received the email completely..

BUT? WHERE IS THE PICTURE? LOL..

I tried and tried and tried. NEED HELP!!

Thank you

I myself am having issues with this upload problem…

Everything has been setup perfectly so to the “FAQ” and yet still it fails to go anywere..

I have noticed there is a “.htaccess” file in the wpcf7_uploads folder which has “Deny from all”

I found that I could not properly upload files when using [file your-file], but I could once I changed the tag to [file file-60]. No idea why!

This is an excellent plugin – thanks for all your hard work :-)

Also discovered: if your uploading file directory isn’t correct, it will cause this plugin to fail. Log in as admin and navigate to Settings >> Miscellaneous.

[file your-file filetypes:gif|png|jpg|jpeg]

set same on the top line is perpect work.

Set up file attachments with a mail is
File attachments:
[your-file]

name is the same in left box and mail box are worked.

I had the upload functionality consistently fail for me and went through all the threads on this website (CHMOD 777, etc) with no success.

For me the form worked perferctly EXCEPT when attaching a file for upload. When clicking submit the activity icon would spin round and round endlessly and the form would not process.

THE PROBLEM WAS IN THIS CODE:
[submit id:submit “Submit”]

It was because I set the ID of the Submit button to ‘submit’. Upon changing the ID to anything else the form worked with file attachments.

PS: I only found this out by using Firebug and checking the errors. That led me to this post: http://groups.google.com/group/jquery-en/browse_thread/thread/7016828517e5ca47

I alsow solved “failed to upload” error as raiderj.
Thanks!

raiderj Says June 11, 2009 at 11:26 am:
Also discovered: if your uploading file directory isn’t correct, it will cause this plugin to fail. Log in as admin and navigate to Settings >> Miscellaneous.

In detail i changed upload dir:
wp-content (was default) > wp-content/uploads.
It is strange, because as description says default folder is “wp-content/uploads”.
Wordpress version 2.8
Thanks all!

This plugin is excellent!

Is it possible for me to return the uploaded file’s path in the email instead of attaching the file itself?

Thanks!

– Keighl

Nice script tnks.

I had the error “failed to upload”.

Thanks to other user I solved it, but with other workaround.

WordPress version 2.8

[WP ADMIN]

Settings >> Miscellaneous – change wp-content to wp-content/uploads

[FILESYSTEM]

wp-content/uploads – didn’t existed, so I created it – be aware of the directorie owner and permissions -.

wp-content/wpcf7_upload – delete OR move it to wp-content/uploads

wp-content/uploads/wpcf7_upload – if doesn’t exist, create it – be aware of the directorie owner and permissions -.

素敵なプラグインをありがとうございます。

contact-form-7.2.0を使わせてもらったのですがファイル添付メールのみうまくいきません。

wpcf7_uploadsフォルダ内にアップロードできないようですが、エラーは一切なく、メッセージ本文などは問題なく送信されます。
関係あるかどうかは不明ですが、上記のJimmyさんと同じく、wpcf7_uploadsフォルダ内に.htaccessが作成され、「Deny from all」と書かれています。

wp-content/uploads/wpcf7_uploads
↑のディレクトリは全て707属性に設定してあります。
WPのメディアアップロードはwp-content/uploadsに正常に出来る状態です。

考えられる原因を教えていただければ幸いです。

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 )

Google photo

You are commenting using your Google 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