>>
Send a PDF (or any other file) as a mail attachment
Here are the latest comments for the resource Send an Email Attachment with PHP.
This work great, just fine for me! I test it... Thanks!
alexxss1986 commented on 19/08/2008, 01:01:16
Code sends email (great) also includes pdf attachment... but when i try to open the pdf, it says: "Adobe Reader could not open xxxx.pdf because it is either not a supported file type or because the file has been damaged (for exampte, it was sent as an email attachment and wasn't correctly decoded)" ... any suggestions?
(adobe reader version 9)
Karen commented on 14/08/2008, 20:12:01
Hmmmm. So Coll !!. I was in a very big problem. now every think ok. actualyi was using some other code. it some time working some time not working. i have to send attachment for my clients. so cool
Piyal Darshana commented on 02/08/2008, 05:21:01
Ignore my comments. Peter has the right idea. You need to define $message after $subject. This variable is what will be visible in the body of the e-mail. The "This is a multi-part message in MIME format" string in the code above isn't actually put in the body of the e-mail, but it appears that some sort of string needs to be there to make the MIME boundary happy.
In other words,
$message = "Visible body of e-mail";
$message = "PDF-This message will not be seen in the body\n\n".
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n".
$message. "\n\n";
andrew commented on 31/07/2008, 18:20:44
Looks like Peter ran into the same issue, but solved it a different way.
andrew commented on 31/07/2008, 17:57:41
In the code snippet "Code: Add the MIME content", you probably need to get rid of the concatenation of $message to itself ...
One of my good friends/coding buddies caught this.
Andrew commented on 31/07/2008, 17:56:37
Great ressource, but I found an error. After the $subject= line, there should be a line, e.g.:
$message = "Here is your text message.";
Peter commented on 23/07/2008, 12:05:05
Tusilla It should work. Well it does for me, The file size maybe an issue (coding) and form data. Might be easier to submit the PDF as XML which you can set sending options.
commented on 19/07/2008, 06:35:56
PHP Warning: fopen(/public_html/pdfs/mypdf.pdf) [function.fopen]: failed to open stream
This should be the path to your PDF file to correct this open sendmailattachment.php and edit on line 29
Warning: filesize mail transport has a max file size to send over the net.
Try correcting the line 29,30,31
Donut commented on 19/07/2008, 06:29:26
This is great thank you for the step by step explanation too. I really needed this exact script for something I'm trying to do at work.
Zach commented on 15/07/2008, 16:51:08
Any ideas on how to do this with a fillable PDF form? I want the user to download the form, fill it in, and then submit the form. The filled form will then be sent as an attachment to an email address. I am using adobe lifecycle to create the form.
Tusilla commented on 15/07/2008, 15:31:36
Sir
I cannot send the messages.This section will be blank But i am able to send and receive attachments Why Please help me....
thanking you
raghavendra M
Raghavendra M commented on 11/07/2008, 10:37:22
Thanks for this -- it worked like a charm. Next step is to learn how to do an html/plain text version -- but this is good enough for now!
brian commented on 09/07/2008, 07:40:46
I can't get this code to work for me... for some reason I get the following message/warning:
The email was sent.
PHP Warning: fopen(/public_html/pdfs/mypdf.pdf) [function.fopen]: failed to open stream: No such file or directory in D:\domains\nctventures.com\wwwroot\sendmailattachment.php on line 29 PHP Warning: filesize() [function.filesize]: stat failed for /public_html/pdfs/mypdf.pdf in D:\domains\nctventures.com\wwwroot\sendmailattachment.php on line 30 PHP Warning: fread(): supplied argument is not a valid stream resource in D:\domains\nctventures.com\wwwroot\sendmailattachment.php on line 30 PHP Warning: fclose(): supplied argument is not a valid stream resource in D:\domains\nctventures.com\wwwroot\sendmailattachment.php on line 31
please help.
Mark commented on 09/07/2008, 03:59:29
I can't get this code to work for me... for some reason I get the following message/warning:
The email was sent.
PHP Warning: fopen(/public_html/pdfs/mypdf.pdf) [function.fopen]: failed to open stream: No such file or directory in D:\domains\nctventures.com\wwwroot\sendmailattachment.php on line 29 PHP Warning: filesize() [function.filesize]: stat failed for /public_html/pdfs/mypdf.pdf in D:\domains\nctventures.com\wwwroot\sendmailattachment.php on line 30 PHP Warning: fread(): supplied argument is not a valid stream resource in D:\domains\nctventures.com\wwwroot\sendmailattachment.php on line 30 PHP Warning: fclose(): supplied argument is not a valid stream resource in D:\domains\nctventures.com\wwwroot\sendmailattachment.php on line 31
please help.
Mark commented on 09/07/2008, 03:55:09
Remove the { } around $fileattname and $fileatttype and it works fine :)
Dan commented on 08/07/2008, 18:27:46
Code is working fine. But while sending pdf file i could not able to open the attachment and it says error message called document damaged or properly decoded
Wester commented on 07/07/2008, 12:08:39
Thank u so much its working well...
sundaresh commented on 07/07/2008, 08:56:25
Thank you so much,I've been trying for two day to send an attachment through php. This code works.
Justin commented on 30/06/2008, 12:29:33
Thank you so much,I've been trying for two day to send an attachment through php. This code works.
When I use this script on my local machine, everything works fine. When I put the script online, I get an 'attachmentless' email that prints the header like a message without an attachment . Is there specification for the server? I am sending a text file (it's actually a comma delimited file) and I am using a "text/plain" content-type.
Nadeem commented on 12/05/2008, 11:28:41
... about my lasta question, already solved it.
If anyone wants to know, all you have to do is repeat the statemente:
the file you are sending is supposed to be at the same map as the file with the mail function -- this works for me fine
tereza commented on 03/04/2008, 12:33:33
Very easy to use, worked perfectly first time.
Really impressed and happy with it, thank you very much.
Alex commented on 01/04/2008, 16:24:14
Spending 4hrs with various code, here i got the ultimate result.
savvy commented on 01/04/2008, 08:58:49
Great script-works fine.
Stefan commented on 30/03/2008, 16:10:04
it won't work for me
yavor commented on 28/03/2008, 14:42:14
I'm sorry to tell you that he wont word by me.. Please can somebody help me?
Steve commented on 12/03/2008, 07:47:16
itis very simple script,thank for this.
sangramsinh sardesai commented on 11/03/2008, 11:06:10
Great Code, thanks a lot!!
2 slight changes I had to make were..
i) Remove last brace to prevent parse error.
ii) Change $to to email address only to get SMTP server to send.
Thanks again!!
Andy commented on 06/03/2008, 16:01:09
The code works perfectly! THANK YOU! I've been struggling to get another person's code to work without any luck. I plugged this in and Voila! It worked the first time!
Thanks for this great resource!
Amanda commented on 05/03/2008, 22:41:44
easy script that you study a bit to fully understand. great work. i was lucky that i wanted to attach a pdf :P so i didnt have to change that much
silvio commented on 04/03/2008, 10:05:34
thanks, thanks, thanks!!!
ares commented on 09/02/2008, 20:09:58
still i did not check it when i check it i will post my comment
haider commented on 06/02/2008, 10:51:01
your code doesn't work
it transmits and display pdf as sum dumped text
not as an attachement and does not make sense
abhinav commented on 19/01/2008, 05:03:45
how can we apply this setting to zip file? i mean application/pdf, what do we have to write for that ?
SoulSmasher commented on 13/12/2007, 22:58:35
what im receiving is garbage, its the 7-bit ASCII conversion of the file. how do i solve this problem?
Thanks
chino commented on 10/12/2007, 09:09:39
thanks a lot - very helpful & accurate.
ben schlessinger commented on 04/12/2007, 22:56:11
Cool!!! I really solution for me...
Thanks, really really thanks
rafa espadada commented on 23/11/2007, 13:48:06
This script is sexy... deffinatly wouldn't say no. Good work!
Kio commented on 14/11/2007, 04:09:43
This worked perfectly . Thank you
Jerica commented on 01/11/2007, 20:35:56
Great.
How attach 2 or more pdf files
Thank you
Alfred commented on 31/10/2007, 22:29:46
it is very good tutorial and I get a good advantage from it
Thank you very much