Cannot open sent ZIP attachment

the mail() function

Moderators: macek, egami, gesf

MacDknife
New php-forum User
New php-forum User
Posts: 3
Joined: Tue Aug 07, 2012 1:09 pm

Cannot open sent ZIP attachment

Postby MacDknife » Tue Aug 07, 2012 1:41 pm

Hi!
I'm pretty new at PHP and sending emails with it. I have tried various scripts to send images and ZIP files as attachments. The problem is on the recieving end. I recieve all the emails and the attached files and can open them - except for Zip files. It doesn't matter which archiver I use, they all say the file is either damaged, corrupt or wrong format. The content seems to be the same though (same file size).

I have Windows 7, 64-bit Pro Swedish and have now even tried updating everything to the latest 64-bit version (Apache 2.4, PHP 5.4.3 and MySQL 5.5) on my local server. I use hMailServer (MySQL database)Same results. I send from the local server to my normal email adress with my ISP. There are no problems opening attached ZIP files sent with "normal" emails.

Anyone with any ideas as to what I've missed or skipped?
Thanks in advance!

MacDknife
New php-forum User
New php-forum User
Posts: 3
Joined: Tue Aug 07, 2012 1:09 pm

Re: Cannot open sent ZIP attachment

Postby MacDknife » Wed Aug 08, 2012 4:44 am

OK - this is weird! I copied the test files (e-post_test.php & 'Uploads/attachment.zip') to an active webserver (http://www.web10.se), where I have a functioning webpage (http://www.skglimma.se) and tested sending from there - same result!! (cannot open the sent ZIP file)

This is the simple code:

<?php
//define the receiver of the email
$to = 'reciever@mail.com';

//define the subject of the email
$subject = 'test email with attachment';

//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));

//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: sender@mail.com\r\nReply-To: sender@mail.com";

//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";

//read the attachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks
$attachment = chunk_split(base64_encode(file_get_contents('Uploads/attachment.zip')));

//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"

--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hello World!!!
This is simple text email message.

--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<h2>Hello World!</h2>
<p>This is something with <b>HTML</b> formatting.</p>
<BR />
<p>Vi vill också kolla svenska tecken <b>äöåÄÖÅ</b></p>

--PHP-alt-<?php echo $random_hash; ?>--


--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: application/zip; name="attachment.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment

<?php echo $attachment; ?>
--PHP-mixed-<?php echo $random_hash; ?>--

<?php

//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();

//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );

//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "E-posten skickat!" : "E-posten kunde inte skickas!";
?>


I copied this script from the web, unfortunately I cannot remember where, as I have tried many different scripts. All with the same result. This script simply tests HTML, as well as Swedish text and attaches the ZIP file. Someone please give me a clue to what the problem is, or even better, a script that you are positive should work.

Thanks!
/MacDknife

MacDknife
New php-forum User
New php-forum User
Posts: 3
Joined: Tue Aug 07, 2012 1:09 pm

Re: Cannot open sent ZIP attachment

Postby MacDknife » Fri Aug 31, 2012 12:24 am

Hi all!
I guess this one stumped you all! There has not been one reply. I have however, managed to find the answer by my self, by continuing to test different scenarios. The problem was MS Outlook!?! When I tested sending the same e-mails to my Yahoo account, as well as opening the emails in my webmail client, everything worked perfectly!

I have told Microsoft about this, so I can only hope that they fix this in their coming updates and not blame something else.

I therefore consider this topic closed.
8)


Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 0 guests