PHP Classes

Mail attachments are corrupted

Recommend this page to a friend!

      MIME E-mail message sending  >  MIME E-mail message sending package blog  >  How Can PHP Send Emai...  >  All threads  >  Mail attachments are corrupted  >  (Un) Subscribe thread alerts  
Subject:Mail attachments are corrupted
Summary:Mail attachments are corrupted
Messages:10
Author:hakan blacksnake
Date:2014-09-03 07:08:27
 

  1. Mail attachments are corrupted   Reply   Report abuse  
Picture of hakan blacksnake hakan blacksnake - 2014-09-03 07:08:27
Thanks a lot for you amazing class!
I was using your it to create ".doc" file and send it as email attachments, i had no problem for years. Now, on the recipient side the attachments are corrupted.
-- I tested the same codes on different web servers on different networks,
-- i tried sending ".docx" and ".pdf" instead of ".doc" files,
-- I tried using smtp class,
but, still no success, all files are corrupted. Do you have any idea to fix this?

here is my code:

<?php
/*
* test_attachment_message.php
*
* @(#) $Header: /home/mlemos/cvsroot/PHPlibrary/mimemessage/test_attachment_message.php,v 1.3 2003/01/29 02:44:33 mlemos Exp $
*
*/

/*
* Trying to guess your e-mail address.
* It is better that you change this line to your address explicitly.
* $from_address="me@mydomain.com";
* $from_name="My Name";
*/
$from_address="hakanxxx@gmail.com";
$from_name="Hakan Sender";

$reply_name=$from_name;
$reply_address=$from_address;
$error_delivery_name=$from_name;
$error_delivery_address=$from_address;

/*
* Change these lines or else you will be mailing the class author.
*/
$to_name="Hakan Receiver";
$to_address="hakankarayilan@gmail.com";



$subject="Test email with attachements";
$email_message=new email_message_class;
$email_message->SetEncodedEmailHeader("To",$to_address,$to_name);
$email_message->SetEncodedEmailHeader("From",$from_address,$from_name);
$email_message->SetEncodedEmailHeader("Reply-To",$reply_address,$reply_name);
$email_message->SetHeader("Sender",$from_address);

/*
* Set the Return-Path header to define the envelope sender address to which bounced messages are delivered.
* If you are using Windows, you need to use the smtp_message_class to set the return-path address.
*/
if(defined("PHP_OS")
&& strcmp(substr(PHP_OS,0,3),"WIN"))
$email_message->SetHeader("Return-Path",$error_delivery_address);

$email_message->SetEncodedHeader("Subject",$subject);

/*
* A message with attached files usually has a text message part
* followed by one or more attached file parts.
*/
$text_message="The Test File from ".$Name." is attached.";
$email_message->AddQuotedPrintableTextPart($email_message->WrapText($text_message));

$text_attachment=array(
"Pragma"=>"public",
"Expires"=>"0",
"Cache-Control"=>"must-revalidate",
"Data"=>"Hello World",
"Name"=>"Test.doc",
"Content-Type"=>"automatic/name",
"Disposition"=>"attachment",
"Content-Transfer-Encoding"=>"binary"
);
$email_message->AddFilePart($text_attachment);

/*
* The message is now ready to be assembled and sent.
* Notice that most of the functions used before this point may fail due to
* programming errors in your script. You may safely ignore any errors until
* the message is sent to not bloat your scripts with too much error checking.
*/
$error=$email_message->Send();
if(strcmp($error,""))
echo "Error: $error\n";
else{
header("Location: http://www.google.com");
}//else?>

  2. Re: Mail attachments are corrupted   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2014-09-03 07:52:05 - In reply to message 1 from hakan blacksnake
I have no idea because corrupted may mean many things. How did you get to that conclusion?

Can you make your script send the message to mlemos at acm dot org?

  3. Re: Mail attachments are corrupted   Reply   Report abuse  
Picture of hakan blacksnake hakan blacksnake - 2014-09-03 08:42:38 - In reply to message 2 from Manuel Lemos
I sent to email my self and when i tried to open the attachment, i got "the file is corrupt and can not be opened" error. This is how i get the conclusion.

I get the script send you a sample pdf attachement to the address you gave.
Thanks a lot for your quick response and help!

  4. Re: Mail attachments are corrupted   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2014-09-03 09:16:41 - In reply to message 3 from hakan blacksnake
The problem is that you are not telling me what program you are using to receive the message that is saying the file is corrupted.

Anyway, the message did not arrive. Try sending to mlemos at gmail dot com. Obviously you should replace at by @ and dot by . .

  5. Re: Mail attachments are corrupted   Reply   Report abuse  
Picture of hakan blacksnake hakan blacksnake - 2014-09-03 09:55:10 - In reply to message 4 from Manuel Lemos
Of course i replaced the strings in your email address.

MS Office 2010 / 2013 both give the same error message when i try to open the attachement.
I sent email to different email addresses, i received with different email clients like MS Outlook 2010 and gmail web client. Result is the same.

Now i'am sending a ".docx" file to the other email address you provided.

  6. Re: Mail attachments are corrupted   Reply   Report abuse  
Picture of hakan blacksnake hakan blacksnake - 2014-09-03 10:32:45 - In reply to message 5 from hakan blacksnake
Additionally,
When i try to open ".pdf" attachment with Adobe Acrobat Standart, it says"Adobe could not open because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)".

  7. Re: Mail attachments are corrupted   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2014-09-03 11:41:35 - In reply to message 5 from hakan blacksnake
I got the message here and I can open the file perfectly.

I think your problem is with whatever is your mail system that is receiving the message.

  8. Re: Mail attachments are corrupted   Reply   Report abuse  
Picture of hakan blacksnake hakan blacksnake - 2014-09-03 16:51:20 - In reply to message 7 from Manuel Lemos
Ok, thanks for your help!

  9. Re: Mail attachments are corrupted   Reply   Report abuse  
Picture of lee charles lee charles - 2016-03-08 08:37:49 - In reply to message 8 from hakan blacksnake
Something went wrong with my pdf reader. I wanna convert pdf to text first. Any suggestion will be appreciated. Thanks in advance.
pqscan.com/pdf-to-text/

  10. Re: Mail attachments are corrupted   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2016-03-08 17:58:37 - In reply to message 9 from lee charles
It depends on what you want to do. Try asking for a package recommendation here detailing your needs, so somebody can give you some advice:

phpclasses.org/recommend_package/