move website to windows server from Linux and function has stopped working

Posted on 2013-09-25
Medium Priority
Last Modified: 2013-10-19

I have a web based system that I have written in php/codeigniter.

It worked fine on a linux server, but I changed hosts to windows server and a bit has stopped working

the system generates a pdf on the fly and attaches it to an email, then sends to a client.  Used to work well... the pdf bit still works (using mpdf)  and they still look good.  But the generation of the email seems to fail... so I am assuming that the way the email is generated is causing problems..

here is some code (simplified and anonymised)

I am passing in the generated pdf ($content) and the name I am giving to the file as $filename, the rest is simple enough...

function send_email($content,$to,$name,$filename, $cc) {
		$content = chunk_split(base64_encode($content));
		$mailto = $to;
		$from_name = 'someone';
		$from_mail = 'someone@comecompany.com';
		$replyto = 'someone@comecompany.com';
		$uid = md5(uniqid(time()));
		$subject = 'Some subject';
		$header = "From: $from_name <$from_mail>\r\n";
		$header .= "Reply-To: $replyto\r\n";
		$header .= "Cc: $cc\r\n";
		$header	.= "Disposition-Notification-To: $from_mail\r\n"; 
		$header	.= "X-Confirm-Reading-To: $from_mail\r\n"; 
		$header .= "X-Priority: 1 (Highest)\r\n";
        $header .= "X-MSMail-Priority: High\r\n";
        $header .= "Importance: High\r\n";
		$header .= "MIME-Version: 1.0\r\n";
		$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
		$header .= "This is a multi-part message in MIME format.\r\n";
		$header .= "--".$uid."\r\n";
		$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
		$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";

		$message = "Please find attached";
		$header .= $message."\r\n\r\n";
		$header .= "--".$uid."\r\n";
		$header .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n";
		$header .= "Content-Transfer-Encoding: base64\r\n";
		$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
		$header .= $content."\r\n\r\n";
		$header .= "--".$uid."--";
		return @mail($mailto, $subject, "", $header);

Open in new window

the email does send, and the file is attached, but the email is blank and the attachment wont open, saying the file is corrupt..

any ideas why it wont work on windows hosting?


Question by:cycledude
  • 2
  • 2
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39522296
It looks to me like it is formatted wrong no matter what hosting.  Your attachment should not be in the header but in the body.  This page http://webcheatsheet.com/PHP/send_email_text_html_attachment.php#attachment shows how to create the MIME boundaries properly.  A different description: http://en.wikipedia.org/wiki/MIME

Author Comment

ID: 39524144
well maybe you should enlighten the guys who created mpdf with your findings

LVL 84

Accepted Solution

Dave Baldwin earned 2000 total points
ID: 39525664
No, I'll settle for just telling you.  The MIME 'standards' were set long before 'mpdf' was written.  Of all of the examples of sending MIME compliant email, the 'mpdf' example is the only one I've seen that puts all that in the headers.


Author Closing Comment

ID: 39584572
Thanks, I havent had time to check it out, but lets hope that this can fix my problem

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This installment of Make It Better gives Media Temple customers the latest news, plugins, and tutorials to make their Grid shared hosting experience that much smoother.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question