[PHP] Attaching a PDF in email (no body text displays)
I am attaching a PDF document to an email, this part works great, however to get this to work it prevents the text in the body of the message to be displayed, what am I doing wrong? Here is the code: $filename = confirmation.pdf; if(!($fp = fopen($filename, r))): $error = Can't open file; echo $error; exit; endif; $boundary = b . md5(uniqid(time())); $boundary=''.$boundary.''; $attach = fread($fp, filesize($filename)); $attach = chunk_split(base64_encode($attach)); $mime = from: [EMAIL PROTECTED]; $mime .= Content-type: multipart/mixed; boundary=$boundary; $mime .= --$boundary\r\n; $mime .= Content-type: application/pdf; name=\confirmation.pdf\\r\n; $mime .= Content-Transfer-Encoding: base64\r\n\r\n; $mime .= Content-Disposition: attachment;\r\n; $mime .= \r\n$attach\n; $mime .= --$boundary\r\n; $mime .= Content-Type: text/HTML; charset=iso-8859-1\r\n; $mime .= Content-Transfer-Encoding: 7bit\r\n\r\n; $mime .= test test test; $mime .= --$boundary--\r\n; mail([EMAIL PROTECTED],Your Confirmation: $confirmation_number,,$mime);
RE: [PHP] Attaching a pdf in email (no body text displays)
SOMEONE ANSWERED THIS FOR YOU I've attached some comments inline. Ade Smith wrote: I am attaching a PDF document to an email, this part works great, however to get this to work it prevents the text in the body of the message to be displayed, what am I doing wrong? Here is the code $filename = confirmation.pdf; if(!($fp = fopen($filename, r))): $error = Can't open file; echo $error; exit; endif; $boundary = b . md5(uniqid(time())); $boundary=''.$boundary.''; $attach = fread($fp, filesize($filename)); $attach = chunk_split(base64_encode($attach)); $mime = from: [EMAIL PROTECTED]; $mime .= Content-type: multipart/mixed; boundary=$boundary; $mime .= --$boundary\r\n; $mime .= Content-type: application/pdf; name=\confirmation.pdf\\r\n; $mime .= Content-Transfer-Encoding: base64\r\n\r\n; $mime .= Content-Disposition: attachment;\r\n; $mime .= \r\n\r\n$attach\n; It's been while, but shouldn't this line read: $mime .= \r\n$attach\r\n; Just to ensure that no extra characters get included witht he file? I don't think it matters much with PDFs, but it would definitely break other files. $mime .= --$boundary\r\n; $mime .= Content-Type: text/HTML; charset=iso-8859-1\r\n; $mime .= Content-Transfer-Encoding: 7bit\r\n\r\n; $mime .= test test test; $mime .= --$boundary\r\n; You forgot the trailing -- here, so this line should read: $mime .= --$boundary--\r\n; Otherwise the mail clients assume there is another part to the MIME message (which defaults to empty). And the last part is always the one that is intended to be viewed. , So it displays the empty one. mail([EMAIL PROTECTED],Your Confirmation: $confirmation_number,test test test test test,$mime); Once again, it's been awhile, but I believe the best way to do this is to put only the main body headers into the header variable ($mime in this case), and put the parts in the body So the body itself is split into the parts. This is probably contributing to the problem as well. Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Attaching a pdf in email (no body text displays)
Unfortunately their suggestion did not work. -Original Message- From: Jay Blanchard [mailto:[EMAIL PROTECTED] Sent: Thursday, July 21, 2005 11:28 AM To: PHP - General Subject: RE: [PHP] Attaching a pdf in email (no body text displays) SOMEONE ANSWERED THIS FOR YOU I've attached some comments inline. Ade Smith wrote: I am attaching a PDF document to an email, this part works great, however to get this to work it prevents the text in the body of the message to be displayed, what am I doing wrong? Here is the code $filename = confirmation.pdf; if(!($fp = fopen($filename, r))): $error = Can't open file; echo $error; exit; endif; $boundary = b . md5(uniqid(time())); $boundary=''.$boundary.''; $attach = fread($fp, filesize($filename)); $attach = chunk_split(base64_encode($attach)); $mime = from: [EMAIL PROTECTED]; $mime .= Content-type: multipart/mixed; boundary=$boundary; $mime .= --$boundary\r\n; $mime .= Content-type: application/pdf; name=\confirmation.pdf\\r\n; $mime .= Content-Transfer-Encoding: base64\r\n\r\n; $mime .= Content-Disposition: attachment;\r\n; $mime .= \r\n\r\n$attach\n; It's been while, but shouldn't this line read: $mime .= \r\n$attach\r\n; Just to ensure that no extra characters get included witht he file? I don't think it matters much with PDFs, but it would definitely break other files. $mime .= --$boundary\r\n; $mime .= Content-Type: text/HTML; charset=iso-8859-1\r\n; $mime .= Content-Transfer-Encoding: 7bit\r\n\r\n; $mime .= test test test; $mime .= --$boundary\r\n; You forgot the trailing -- here, so this line should read: $mime .= --$boundary--\r\n; Otherwise the mail clients assume there is another part to the MIME message (which defaults to empty). And the last part is always the one that is intended to be viewed. , So it displays the empty one. mail([EMAIL PROTECTED],Your Confirmation: $confirmation_number,test test test test test,$mime); Once again, it's been awhile, but I believe the best way to do this is to put only the main body headers into the header variable ($mime in this case), and put the parts in the body So the body itself is split into the parts. This is probably contributing to the problem as well. Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Attaching a pdf in email (no body text displays)
[snip] Unfortunately their suggestion did not work. [/snip] Then, instead of just reposting your original message, let us know that it didn't work. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Attaching a pdf in email (no body text displays)
[snip] Then, instead of just reposting your original message, let us know that it didn't work. [/snip] Forgot to say that there is a tutorial on http://www.zend.com by Coggershall telling how to do e-mail with attachements. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Attaching a PDF in email (no body text displays)
Personally I use the MimeMail class, that works a treat, http://www.phpguru.org/static/mime.mail.html Their are two versions, one php4 one php5, or install via pear. JB Ade Smith wrote: I am attaching a PDF document to an email, this part works great, however to get this to work it prevents the text in the body of the message to be displayed, what am I doing wrong? Here is the code: $filename = confirmation.pdf; if(!($fp = fopen($filename, r))): $error = Can't open file; echo $error; exit; endif; $boundary = b . md5(uniqid(time())); $boundary=''.$boundary.''; $attach = fread($fp, filesize($filename)); $attach = chunk_split(base64_encode($attach)); $mime = from: [EMAIL PROTECTED]; $mime .= Content-type: multipart/mixed; boundary=$boundary; $mime .= --$boundary\r\n; $mime .= Content-type: application/pdf; name=\confirmation.pdf\\r\n; $mime .= Content-Transfer-Encoding: base64\r\n\r\n; $mime .= Content-Disposition: attachment;\r\n; $mime .= \r\n$attach\n; $mime .= --$boundary\r\n; $mime .= Content-Type: text/HTML; charset=iso-8859-1\r\n; $mime .= Content-Transfer-Encoding: 7bit\r\n\r\n; $mime .= test test test; $mime .= --$boundary--\r\n; mail([EMAIL PROTECTED],Your Confirmation: $confirmation_number,,$mime); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Attaching a PDF in email (no body text displays)
Ade Smith wrote: I am attaching a PDF document to an email, this part works great, however to get this to work it prevents the text in the body of the message to be displayed, what am I doing wrong? Here is the code: $filename = confirmation.pdf; if(!($fp = fopen($filename, r))): $error = Can't open file; echo $error; exit; endif; $boundary = b . md5(uniqid(time())); $boundary=''.$boundary.''; $attach = fread($fp, filesize($filename)); $attach = chunk_split(base64_encode($attach)); $mime = from: [EMAIL PROTECTED]; $mime .= Content-type: multipart/mixed; boundary=$boundary; $mime .= --$boundary\r\n; $mime .= Content-type: application/pdf; name=\confirmation.pdf\\r\n; $mime .= Content-Transfer-Encoding: base64\r\n\r\n; $mime .= Content-Disposition: attachment;\r\n; $mime .= \r\n$attach\n; $mime .= --$boundary\r\n; $mime .= Content-Type: text/HTML; charset=iso-8859-1\r\n; $mime .= Content-Transfer-Encoding: 7bit\r\n\r\n; $mime .= test test test; $mime .= --$boundary--\r\n; mail([EMAIL PROTECTED],Your Confirmation: $confirmation_number,,$mime); You have nothing in the body part of the mail function http://us2.php.net/manual/en/function.mail.php mail($to, $subject, $message, $headers); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Attaching a PDF in email (no body text displays)
sorry, i think i misunderstood his problem. I didn't get the replies to his original post until after I sent mine jzf Joseph wrote: Ade Smith wrote: I am attaching a PDF document to an email, this part works great, however to get this to work it prevents the text in the body of the message to be displayed, what am I doing wrong? Here is the code: $filename = confirmation.pdf; if(!($fp = fopen($filename, r))): $error = Can't open file; echo $error; exit; endif; $boundary = b . md5(uniqid(time())); $boundary=''.$boundary.''; $attach = fread($fp, filesize($filename)); $attach = chunk_split(base64_encode($attach)); $mime = from: [EMAIL PROTECTED]; $mime .= Content-type: multipart/mixed; boundary=$boundary; $mime .= --$boundary\r\n; $mime .= Content-type: application/pdf; name=\confirmation.pdf\\r\n; $mime .= Content-Transfer-Encoding: base64\r\n\r\n; $mime .= Content-Disposition: attachment;\r\n; $mime .= \r\n$attach\n; $mime .= --$boundary\r\n; $mime .= Content-Type: text/HTML; charset=iso-8859-1\r\n; $mime .= Content-Transfer-Encoding: 7bit\r\n\r\n; $mime .= test test test; $mime .= --$boundary--\r\n; mail([EMAIL PROTECTED],Your Confirmation: $confirmation_number,,$mime); You have nothing in the body part of the mail function http://us2.php.net/manual/en/function.mail.php mail($to, $subject, $message, $headers); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Attaching a pdf in email (no body text displays)
I am attaching a PDF document to an email, this part works great, however to get this to work it prevents the text in the body of the message to be displayed, what am I doing wrong? Here is the code $filename = confirmation.pdf; if(!($fp = fopen($filename, r))): $error = Can't open file; echo $error; exit; endif; $boundary = b . md5(uniqid(time())); $boundary=''.$boundary.''; $attach = fread($fp, filesize($filename)); $attach = chunk_split(base64_encode($attach)); $mime = from: [EMAIL PROTECTED]; $mime .= Content-type: multipart/mixed; boundary=$boundary; $mime .= --$boundary\r\n; $mime .= Content-type: application/pdf; name=\confirmation.pdf\\r\n; $mime .= Content-Transfer-Encoding: base64\r\n\r\n; $mime .= Content-Disposition: attachment;\r\n; $mime .= \r\n\r\n$attach\n; $mime .= --$boundary\r\n; $mime .= Content-Type: text/HTML; charset=iso-8859-1\r\n; $mime .= Content-Transfer-Encoding: 7bit\r\n\r\n; $mime .= test test test; $mime .= --$boundary\r\n; mail([EMAIL PROTECTED],Your Confirmation: $confirmation_number,test test test test test,$mime);
Re: [PHP] Attaching a pdf in email (no body text displays)
I've attached some comments inline. Ade Smith wrote: I am attaching a PDF document to an email, this part works great, however to get this to work it prevents the text in the body of the message to be displayed, what am I doing wrong? Here is the code $filename = confirmation.pdf; if(!($fp = fopen($filename, r))): $error = Can't open file; echo $error; exit; endif; $boundary = b . md5(uniqid(time())); $boundary=''.$boundary.''; $attach = fread($fp, filesize($filename)); $attach = chunk_split(base64_encode($attach)); $mime = from: [EMAIL PROTECTED]; $mime .= Content-type: multipart/mixed; boundary=$boundary; $mime .= --$boundary\r\n; $mime .= Content-type: application/pdf; name=\confirmation.pdf\\r\n; $mime .= Content-Transfer-Encoding: base64\r\n\r\n; $mime .= Content-Disposition: attachment;\r\n; $mime .= \r\n\r\n$attach\n; It's been while, but shouldn't this line read: $mime .= \r\n$attach\r\n; Just to ensure that no extra characters get included witht he file? I don't think it matters much with PDFs, but it would definitely break other files. $mime .= --$boundary\r\n; $mime .= Content-Type: text/HTML; charset=iso-8859-1\r\n; $mime .= Content-Transfer-Encoding: 7bit\r\n\r\n; $mime .= test test test; $mime .= --$boundary\r\n; You forgot the trailing -- here, so this line should read: $mime .= --$boundary--\r\n; Otherwise the mail clients assume there is another part to the MIME message (which defaults to empty). And the last part is always the one that is intended to be viewed. , So it displays the empty one. mail([EMAIL PROTECTED],Your Confirmation: $confirmation_number,test test test test test,$mime); Once again, it's been awhile, but I believe the best way to do this is to put only the main body headers into the header variable ($mime in this case), and put the parts in the body So the body itself is split into the parts. This is probably contributing to the problem as well. Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php