473,581 Members | 2,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

corrupt file sending email attachment

Hi,

I am sending a file from the server as an email attachment. The file
is being attached no problem and sending the email, but I get an error
when I try to open it saying it is corrupt. Obviuosly, the file is
fine on the server, so the attachment code I am using must be
corrupting it, but I dont know what it is:

// send email with attachment
function emailAttachment ($to, $subject, $message, $name, $email,
$file) {
$fp = fopen($file, "rb");
$fcontent = fread($fp, filesize($file) );
fclose($fp);
$data = chunk_split(bas e64_encode($fco ntent));
$mime_boundary = md5(uniqid(time ()));
$file_name = basename($file) ;
$header = "From: " . $name . "<" . $email . ">\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed;\r\n";
$header .= " boundary=\"" . $mime_boundary . "\"\r\n";
$content = "This is a multi-part message in MIME format.\r\n\r\n ";
$content .= "--" . $mime_boundary . "\r\n";
$content .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$content .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$content .= $message . "\r\n\r\n";
$content .= "--" . $mime_boundary . "\r\n";
$content .= "Content-Type: image/jpeg; name=\"" . $file_name .
"\"\r\n";
$content .= "Content-Transfer-Encoding: base64\r\n";
$content .= "Content-Disposition: attachment; filename=\"" .
$file_name . "\"\r\n\r\n ";
$content .= $data . "\r\n";
$content .= "--" . $mime_boundary . "--";
if (mail($to, $subject, $content, $header)) {
return true;
} else {
return false;
}
}

I am receiving the email on a Mac, will this cause any errors?
I look forward to any help.

Paul
Jul 17 '05 #1
3 7032
Hello,

On 05/26/2004 12:31 PM, Paul Lamonby wrote:
Hi,

I am sending a file from the server as an email attachment. The file
is being attached no problem and sending the email, but I get an error
when I try to open it saying it is corrupt. Obviuosly, the file is
fine on the server, so the attachment code I am using must be
corrupting it, but I dont know what it is:


It is hard to tell. It seems correct.

You may want to try this throughly tested class that also supports
sending messages with attachments to see if you experience the same
problem. Just let me know if your problem is not solved:

http://www.phpclasses.org/mimemessage

--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #2
pa**@popimages. com (Paul Lamonby) wrote in message news:<86******* *************** ****@posting.go ogle.com>...
Hi,

I am sending a file from the server as an email attachment. The file
is being attached no problem and sending the email, but I get an error
when I try to open it saying it is corrupt.

<snip>

Perhaps you should try with <http://phpmailer.sourc eforge.net/>

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #3
Dunno much about sending email attachments, but maybe it is a character
encoding problem. What type of character encoding does base64_encode()
return? In your header, you seem to be assuming it's western latin.
Maybe it's not.

have you tried removing chunk_split()?

Paul Lamonby wrote:
Hi,

I am sending a file from the server as an email attachment. The file
is being attached no problem and sending the email, but I get an error
when I try to open it saying it is corrupt. Obviuosly, the file is
fine on the server, so the attachment code I am using must be
corrupting it, but I dont know what it is:

// send email with attachment
function emailAttachment ($to, $subject, $message, $name, $email,
$file) {
$fp = fopen($file, "rb");
$fcontent = fread($fp, filesize($file) );
fclose($fp);
$data = chunk_split(bas e64_encode($fco ntent));
$mime_boundary = md5(uniqid(time ()));
$file_name = basename($file) ;
$header = "From: " . $name . "<" . $email . ">\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed;\r\n";
$header .= " boundary=\"" . $mime_boundary . "\"\r\n";
$content = "This is a multi-part message in MIME format.\r\n\r\n ";
$content .= "--" . $mime_boundary . "\r\n";
$content .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$content .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$content .= $message . "\r\n\r\n";
$content .= "--" . $mime_boundary . "\r\n";
$content .= "Content-Type: image/jpeg; name=\"" . $file_name .
"\"\r\n";
$content .= "Content-Transfer-Encoding: base64\r\n";
$content .= "Content-Disposition: attachment; filename=\"" .
$file_name . "\"\r\n\r\n ";
$content .= $data . "\r\n";
$content .= "--" . $mime_boundary . "--";
if (mail($to, $subject, $content, $header)) {
return true;
} else {
return false;
}
}

I am receiving the email on a Mac, will this cause any errors?
I look forward to any help.

Paul

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2407
by: AspDotNetDeveloper | last post by:
I'm trying to troubleshoot why my ASP application can no longer send file attachments larger than 100K, and I have eliminated many possibilities already, but I'm running out of ideas. I think I have it narrowed down to an Outlook Express update that is installed on the Win 2K Server, but when I try to remove the update, then the application...
5
2803
by: Nick Z. | last post by:
When using SmtpClient and sending a message with an attached file using SendAsync(...), if I add File.Delete(pathToAttachedFile) in the SendCompleted event handler I get a file in use exception. Is there a way to overcome this problem? Thanks, Nick Z.
14
2372
by: Manish | last post by:
The project I am developing doesn't involves database. I want to parse the mailbox file (.mbx) and store the summary in the text file for fast retrieval and display of information in the Inbox page. The sugegsted format are as: #1 ID : Subject : To Address: From Address...etc...
1
5978
by: kierenj | last post by:
Hi, I'm trying to send a zipfile to a client using Content-Disposition: attachment. Done it before and it works fine. My code is below: context.Response.Buffer = false; System.IO.MemoryStream stream = ArchiveUtil.CreateArchive(new string { "c:\\windows\
7
9874
by: iporter | last post by:
I use the code below to authorise the download of certain files. Thus, instead of linking to the file in a wwwroot directory, I link to this code with the filename as a parameter, and the script streams the file if the user is authorised. This has worked fine on PDFs, DOCs, XLS, etc. until today, and 18MB file presents the error message...
1
3486
by: krishan123456 | last post by:
i have tried to send email with attached doc file but when i receive the mail i find the attached file in encoded text instead of actuall attachment.the code that i used to send an email is given below. function SendMail123($From,$FromName,$To,$ToName,$Subject,$Text,$Html,$AttmFiles){ $OB="----=_OuterBoundary_000";...
0
2472
by: prasenjit2007 | last post by:
I have a main form for inputing the (to/from/mesg/file) with the following code:- <html> <body> <table> <tr> <td>To:</td> <td><input type="text" name="to" size="50" value="pras_sandilya@rediffmail.com"></td> </tr>
4
9077
by: Seguros Catatumbo | last post by:
Hi guys, i am having trouble deleting a file after sending an email. The file is in use. Here's the code: String texto = "Test"; System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(); System.Net.Mail.MailMessage correo = new
7
8551
by: Paridevi | last post by:
Hai , i want to send email in .Net Using OutLook Express,My Project is Web Application using vb.Net 2003 with SQL Server 2000.I have searched a lot in Google, but ican't get any details. Pls its urgent for me. Can any one give me any idea about this. Thanks in advance ...
0
8304
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8175
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6553
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5674
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3827
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1403
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1138
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.