Jump to content

Trying to send a pdf as an attachement with mail()


scotch33

Recommended Posts

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');

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.