How to send an email with attached files

Back to php.

*phphp    (2009-09-22)
How to send an email with attached files


I would like to know how to send an email with attached files with a PHP script, does anyone have an example that works and that would allow me to send any kind of files in an email automatically generated by a PHP server?

Thank you.

(more options below)

*32b0ba    (2009-09-22 17:56:48)
How to send attached files

Hi, here is the script I use to send attached files.


  $boundary = "_".md5 (uniqid (rand()));

  $attached_file = file_get_contents($file_name); //file name ie: ./image.jpg
  $attached_file = chunk_split(base64_encode($attached_file));

  $attached = "\n\n". "--" .$boundary . "\nContent-Type: application; name=\"$file_name\"\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename=\"$file_name\"\r\n\n".$attached_file . "--" . $boundary . "--";

  $headers ="From: ".$my_email." \r\n";
  $headers .= "MIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"$boundary\"\r\n";

  $body = "--". $boundary ."\nContent-Type: text/plain; charset=ISO-8859-1\r\n\n".$message . $attached;



Hope it helps

*fetutu    (2011-01-26 17:02:50)
13 years ago

piece jointe piece jointe piece

*jigaba    (2012-05-20 21:15:17)
11 years ago

You must replace this:
$headers ="From: ".$my_email." \r\n";
  $headers .= "MIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"$boundary\"\r\n";

by this:
$headers ="From: ".$my_email." \n";
  $headers .= "MIME-Version: 1.0\nContent-Type: multipart/mixed;\n boundary=\"$boundary\"\n";


pwhjenny    (2012-10-18 15:41:18)
11 years ago

You can refer below link for the same:

See also

More websites

You must register to see these links, as this is a collaborative page, then you may change the order of the links by clicking the icons before the titles.

Other websites

The following links might be less relevant, please change their ranks if you find them useful.

 YouSendIt - Send large files - transfer delivery - FTP Replacement
  1. = free_trials_left) files_to_be_charged = (files_selected -
  2. Do you want to proceed with sending notification(s) for your
 DOS e-mail - automate email attachment sending
febooti > products/command line email/online help/commands/dos e mail automate a

 SendThisFile | Send Large Files with the Trusted File Transfer Service

CBS, CBS Corporation, and the CBS logo are registered trademarks of...
Click the SendThisFile button! The recipient...

 How do I attach a large file to emails or send a large email attachment?

Hotmail problem - original message not attached in forwards and...
CAPTCHA definition - Why do you need to type the two...

 Attach and Send Any File Type with GMail Like EXE, ZIP, Videos; Trick GMail Antivirus Scanner - Digital Inspiration
labnol.blogspot > 2005/12/cheat gmail antivirus scanner attach

: Yes, it is against the GMail TOS to send viruses in email but...
you can use these GMail hacks to send program file (exe), virus...

 How to Send a File Attachment with Windows Live Hotmail - About Email
email.about > cs/hotmailtips/qt/et060102.htm

 Send File - Easily email large files
send file

Enter the email address of the person to receive your...

 Attachment - Using email - Help - Virgin Media
virginmedia > help/email/using/attachment.php

 Email multiple file attachment from Solairs / AIX / HP-UX UNIX/ Linux command line
cyberciti > faq

Linux and UNIX Mail Command to send and receive...
Howto run a shell script without changing file access...

 How to Send Big Email Attachments Bypass Attachment Limit Restriction
blogsdna > 1363/send email attachment files of any size with existing email acco

Send Email Attachment Files of Any Size with Existing Email Account...
Split Larger Files into Smaller Zip Files with Akhir Split...
How to Get Back Stolen/Hacked Windows Live Hotmail Email...

 Send Email from oracle with file attached" - Forums
forums.dbasupport > forums/s

desc quot_ole Name Null? Type...
'application/winzip', 16 p_attachment_file_name...
'application/winzip', 16 p_attachment_file_name...

 SmartAttach - Send Secure Email Attachments and Large Attachment Files
icewarp > SmartAttach

IceWarp SmartAttach ™ is a new technology that gives senders...

 How To Send Mail with Attachment in PHP
xahlee > php/send mail attachment

 Send Email Attachments - Compress Large Files
livinginternet > e/ea att send.htm

Be careful you don't send large attachments to people...

 Email File Attachment Limits
accellion > solutions/email file attachment limits

 Create and Send that killer HTML Email Newsletter with G-Lock EasyMail

(function(){ function rungsom() { var gsomForm =...
and See for Yourself How Easy it Really Is to Send Stunning Email...
How to Avoid SMTP Server Restrictions Using G-Lock...

 Send Email with Attachment from the File Upload - Forum
novahq > forum/s

 How to Send Large Files Via Email ~ Chris Pirillo

Banana Republic - 25-30% off Purchase using coupon code...
Barcelo Hotels - 5% off Purchase using coupon code...
Space Problem Partiton full of data Change drive...

 Send email with attached file : Email « Components « ASP.Net
java2s > Code/ASP/Components/Sendemailwithattachedfile.htm

 Send a presentation that opens automatically in email
pptfaq > FAQ00341.htm

Sounds/Movies don't play, images disappear or links break when I move...

 Secure Webmail, Secure Email Help
4securemail > webmail help/help content/send email.php

To compose and send a new secure email message, just click on the...
Any time during or after you have composed a message, you can have...
You can save any emails that you plan to use again, or those...

 How to attach and send large files via Outlook » Software for Enterprise
wareprise > 2009/05/14

 Create And Email PDF File 'On The Fly' With PHP
astahost > info.php/Create Email Pdf File 39on Fly39 Php t6334

This textarea will convert to Rich-Text automatically (IE, Firefox,...
Searching Video's for create, email, pdf, file, fly,...

 How to Send an Email - Teaching and Learning Tools - UW-Superior
uwsuper > teachingtools/learn/sendemail.cfm

 How to Send Email Attachments
mediacollege > internet/email/attachments

Create a new email message and enter the usual details (recipient...

 Send Large Files: How To Transfer Huge Files Without Email - Mini-Guide, Part 1

How to Send Large Files without Email: Best Services Online -...
: All large files you need to transfer are sent to your recipient(s)...
: Sending large files requires that you upload your file to an...

 How can I send or receive an email with an attached file larger than 10 MB? | Just ask Gemalto
justaskgemalto > en/surfing/tips

 Why Attached Microsoft Documents Are A Bad Thing
cs.uit > ~tobias/NEW/word rejection

 Automatically Email - Help
watchdirectory > wdhelp/plugins/wdopAutoEmail

If this option is selected it can take a long time before the...
The text you enter here will be added before all individual email...
The text you enter here will be added after all individual email...

 Send big files the easy way. Files too large for email attachments? No problem!

 PHP: Sending Email (Text/HTML/Attachments)
webcheatsheet > PHP/send email text html attachment.php

//copy current buffer contents into $message variable and delete...
//read the atachment file contents into a string,...
Blocking access to the login page after three unsuccessful login...

 Send an email attachment with PHP « Texelate’s Blog
texelate > blog/send email attachment with php

 PC Hell: What is the winmail.dat file attached to emails
pchell > support/winmaildat.shtml

Bookmark and Share this Article on PCHELL with these Social...
How to Fix Problem when Windows Security Center reports multiple...
How to Fix Problem of Limited or No Connectivity After installing...

 FAQ 3 - Email, Cleaning
scantips > faq3

JPG compresson squeezes the data to be a very small file, which is...
menu to find that image, to send it with your email...

 Upload - Send an email with attachment
motobit > help/scptutl/sa271.htm

'get source form fields - From, To, Subject and...

 How to send an email with an attached file ?
mail.python > pipermail/python list/2003 June/211678

netogram > att.htm

function disableselect(e){ return false } function...
ATTACH FILE, and then select the file you wish to attach to the...
Attach Document) or click the Attach button on the...

 send a .zip file as an attachment in an email with Perl [Archive] -
codingforums > archive/index.php/t 101249

hi, i'll give that a go - but i'm not getting any error...

 Attachment in email wont open
en.kioskea > forum/affich 23943 attachment in email wont open

similar problem when sending homework to school i just changed it to...
How to add attchment pictures in internet explorer...
- Sep 12, 2008 9:36am BST - Last answer on Sep 30, 2010 6:27pm BST...


Guest name   (option)     Register
Please sum : 2815 + seven  

كيف أن يرسل بريد إلكترونيّ مع يرب    (ar)
Как да изпрати по адрес на електр    (bg)
Jak poslat e-mail s připojené spisy    (cs)
Hvordan kan sende en e-mail med knyttet sagsakter    (da)
Wie man ein email mit angebrachten Akten sendet    (de)
Πώς να στείλει ένα ηλεκτρονικό τ    (el)
Cómo enviar un email con los archivos unidos    (es)
چگونه به ارسال پرونده هاي مربوط ب    (fa)
Miten on toimitettava sähköpostitse liitteenä kanssa asia    (fi)
Comment envoyer un email avec les dossiers ci-joints    (fr)
Yaya aiki a aika 'i-mel' da ƙawanen fayilolin    (ha)
כיצד שלח במהלך אימייל עם פנסים קב    (he)
भेजने किस प्रकार से सम    (hi)
Hogyan e-mail küldése a csatolt fájlok    (hu)
付けられたファイルが付いている電子メール    (ja)
붙어 있던 파일을 가진 전자 우편을 보내는    (ko)
Hoe te om een e-mail met dossiers in bijlage te verzenden    (nl)
Hvordan å sende en e-post med festes filer    (no)
Jak wysłać e-mail z dołączonym plików    (pl)
Como emitir um email com limas unidas    (pt)
Cum sa trimita un e-mail cu atasate dosarele    (ro)
Как послать email с прикрепленными    (ru)
Kako će poslati e-sa priloženom datoteke    (sr)
Hur man överför en e-post med fäst sparar    (sv)
ว่าจะส่งอีเมลที่ยึดต    (th)
Nasıl gönderebilirsiniz ve eklenmiş dosyalar    (tr)
کس طرح ایک ای میل بھیجنے کے ساتھ م    (ur)
如何送电子邮件与附加的文件    (zh)

Trackbacks : If you talked about this article in your blog or website, you may instantly get a backlink 
There's no trackback at the moment.