Corrupted PDF email attachment using PHP mail script

I have the phpinfo page, you can delete it from your server now… :wink:

Edit: has your host not upgraded php yet? this is a really old version…

Thanks. This is the client’s server that we are doing this project for.

I’m surprised the hosting company hasn’t upgraded. I wonder if we get Cpanel access – if we could do it for them.

I don’t see anything there that is causing this issue. :frowning:

Aside from this you should send the hosting company a polite email asking if they can upgrade php, unless there is a serious reason not to i don’t see why they would refuse.

Anyway, back to this problem, can you post me the entire page that you want this script slotted into, i’ll see what i can do.

Bummer!.

Ok, so this HTML code is basically a form input that asks the user for the email address and then calls the script once you submit – this appears on the mobile-hosted cloud server (not the client’s server):

[code]













Share File:





Enter Email Address:

Send PDF File

[/code]

And this is email20.php in its entirety as it lives on the client’s server in the folder /mobile/email20.php:

[php]<?php
$file_path = “…/images/drawings_walkway/w1.pdf”; // server path where file is placed
$file_path_type = “application/pdf”; // File Type
$file_path_name = “w1.pdf”; // this file name will be used at reciever end
$from = "[email protected]"; // E-mail address of sender
$to = $_POST[‘email’]; // E-mail address of reciever
$subject = "Drawing from "; // Subject of email
$message = “Thank you for downloading the Walkway Canopy with Beams PDF file from xxxxxxx.net. For a free estimate or budget number on a canopy, please email us at [email protected]. Please call xx-xxx-xxxx … can assist you with your next project.”;

$file = fopen($file_path, ‘rb’);
$data = fread($file,filesize($file_path_name));
fclose($file);
$encoded = chunk_split(base64_encode($data));
$mime_boundary = md5(uniqid(time()));

$header = ‘’;
$header .= “From: " . $from . “\r\n”;
$header .= “MIME-Version: 1.0\r\nContent-Type:”.” multipart/mixed;boundary="" . $mime_boundary . “”;\r\n";
$header .= “charset=“iso-8859-1”\r\nContent-Transfer-Encoding:”.“7bit\r\n\n”;
$header .= “If you are reading this, your mail client does not support MIME.\r\n\n”;
$header .= “–” . $mime_boundary . “\r\n”;
$header .= “Content-Type: text/html; charset=“iso-8859-1”\r\n”;
$header .= “Content-Transfer-Encoding: 7bit\r\n\n”;
$header .= $message . “\r\n\n”;
$header .= “–” . $mime_boundary . “\r\n”;
$header .= “Content-Type: " . $file_path_type . “; name=”” . $file_path_name . “”\r\n";
$header .= “Content-Transfer-Encoding: base64\r\n”;
$header .= “Content-Disposition: attachment\r\n\n”;
$header .= $encoded . “\r\n”;
$header .= “–” . $mime_boundary . “–\r\n”;

if(mail($to, $subject, $message, $header)) {
echo “File sent!”;

} else {
echo ‘Failed’;
}
?>[/php]

And yet it works in gmail but not in Outlook. I wonder if I could try and host all these files on my company’s server…if it might work better.

I just updated the location of the email file that you sent me within the html file on the mobile site creation application – and also moved the file to our company’s server.

When I did, there was:

  1. no email attachment
  2. the following output in the text body of the email:

[b]Content-Type: multipart/mixed;boundary=“cb6f2cc4b76b3b580970f13f170bf89a”;

Return-Path: [email protected]
X-OriginalArrivalTime: 31 Jan 2014 16:27:59.0063 (UTC) FILETIME=[676A6E70:01CF1EA1]

charset=“iso-8859-1”

Content-Transfer-Encoding:7bit

If you are reading this, your mail client does not support MIME.

–cb6f2cc4b76b3b580970f13f170bf89a

Content-Type: text/html; charset=“iso-8859-1”

Content-Transfer-Encoding: 7bit

Thank you…urls hidden by mod…

–cb6f2cc4b76b3b580970f13f170bf89a

Content-Type: application/pdf; name=“w1.pdf”

Content-Transfer-Encoding: base64

Content-Disposition: attachment

–cb6f2cc4b76b3b580970f13f170bf89a–

Thank you for downloading the Walkway Canopy with Beams PDF…urls hidden by mod…

I don’t understand why it seems to work on your server and not mine or the client’s. Again, we are using the entire snippet you created as the whole file – are there pieces to the whole php file that I need to add?

Red,

I decided to take the URL that works from your server and post it on my mobile staging site – in an attempt to see if the mobile site’s cloud-server was somehow causing interference issues with encoding the PDF.

Naturally, it worked beautifully. You do great work! Granted, the file is still hosted on your server and I had to append your URL with my email address to make it into a link for testing purposes. Obviously not a longer term solution. In reality, my script will need to be hosted on either my client server or my company’s server – and it will need to ask the visitor for their email address.

but at least now we know for sure that it isn’t the mobile site’s server causing the error.

http://www.xxxxxxx.com/urlhiddenbymod

I posted the URL above in case you wanted to see a preview of how I made your link into a blue button. If you select the button, it fires off an email with the proper attachment and email body copy to my email account.

Any idea why this might not be performing satisfactorily on my end when hosting this file?
Let me know if you need more access – and an email where I can send it to. I owe you an entire pot of coffee at this point…not just a cup :wink:

All done. :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service