scotch33 Posted November 12, 2007 Share Posted November 12, 2007 Hi there, I am having a bit of bother with sending a pdf as an attachment to an automated e-mail send to customers requesting a brochure. I have the mail and attachment working but when I try to open the pdf it says it cannot recognise the filetype. I have looked around and everywhere I have looked the content type for PDF as an attachemnt is 'application/pdf'. I have copied my code below - if anyone can see where I am going wrong I would appreciate the info. Thanks! John $headers = "From: info@newmaticelevators.com \r\n"; $headers .= "Reply-To: info@newmaticelevators.com \r\n"; $headers .= "Bcc: \r\n"; $recipient = $_SESSION['email']; $subject = "Your brochure request from the Newmatic Elavators website"; $bound_text = "antelope2574017"; $bound = "--".$bound_text."\r\n"; $bound_last = "--".$bound_text."--\r\n"; $headers .= "MIME-Version: 1.0\r\n" ."Content-Type: multipart/mixed; boundary=\"$bound_text\""; $message .= "If you can see this MIME than your client doesn't accept MIME types!\r\n" .$bound; $message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n" ."Content-Transfer-Encoding: 7bit\r\n\r\n". "<html> <head> <title>A brochure request from the Newmatic Elevators website</title> </head> <body><p>Dear ".$_SESSION['title']." ".$_SESSION['surname']."</p> <p>You requested a brochure from the Newmatic elevators website.</p><p>Your brochure was requested as a PDF and is attached to this e-mail. Should you have any futher requests please feel free to contact us on the details below.</p><p>Yours sincerely<br /><br />The Newmatic Elevators Team.</p>The Stag House<br /> Wooburn Town<br /> High Wycombe<br /> Buckinghamshire<br /> HP10 0PN<br /> <br /> Phone: 01628 523977<br /> Fax: 01628 529130<br /> <a href='mailto:info@newmaticelevators.com'>info@newmaticelevators.com</a></body></html>\r\n" .$bound; $file = file_get_contents("http://www.newmaticelevators.com/pdfs/NE_brochure.pdf"); $message .= "Content-Type: application/pdf; name=\"NE_brochure.pdf\"\r\n" ."Content-Transfer-Encoding: base64\r\n" ."Content-disposition: attachment; file=\"NE_brochure.pdf\"\r\n" ."\r\n" .chunk_split(base64_encode($file)) .$bound_last; mail($recipient,$subject,$message,$headers); // end send a confirmation to the requester header('Location: http://www.newmaticelevators.com/download/brochure_request_completed.php'); Quote Link to comment Share on other sites More sharing options...
aschk Posted November 12, 2007 Share Posted November 12, 2007 Hmm, interesting. Never attempted something quite as similar but the code looks ok. This may seem like a simple answer, but are you sure that the machine you're testing it on recognises the .pdf in the email as a pdf file? Does it show the mini-icon? Have you got adobe reader installed? I'd be curious to find out, what happens you try try and echo out the contents of $file, and send the application/pdf header straight to the browser? Quote Link to comment Share on other sites More sharing options...
scotch33 Posted November 12, 2007 Author Share Posted November 12, 2007 ah - that's a good idea - will try the output straight to browser and see what the state of play is. the other bits - yes all good on the pc I am testing on, all needed elements are in place. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.