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?>