473,383 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

sending files attached via mail. what's wrong?

i wanna send html files (even *.doc) in the body of a mail with this code:

<?
$userfile = "file.html";
$fp = fopen($userfile, "r");
$file = fread($fp, filesize($userfile));
$file = chunk_split(base64_encode($file));

$email_boundary = md5(uniqid(time()));
$email_headers = "MIME-Version: 1.0\r\n";
$email_headers .= "Content-type: multipart/mixed;boundary=\"$email_boundary
\"";
$email_headers .= "X-attachments: $file\n";
$email_headers .= "\r\n\r\n";

$email_body = "-$email_boundary\n";
$email_body .= "Content-type: text/html; charset=iso-8859-1\r\n";
$email_body .= "Content-transfer-encoding: 8bit\r\n\r\n";
$email_body .= "-$email_boundary\r\n";
$filename = basename($userfile);
$email_body .= "Content-type: application/octet-stream; name=$filename\r\n";
$email_body .= "Content-transfer-encoding:base64\r\n\r\n";
$email_body .= $file. "\r\n\r\n";
$email_body .= "--$email_boundary--";

mail("em***@destinatario.it", "Invio", $email_headers, $email_body);

?>

unfortunatley, even if the mail arrive, in the body i read only the code of
the file but cannot read it.
WHERE IS THE MISTAKE?
PLEASE HELP!!!!!!

daniele

p.s. i also tried this:
mail("em***@destinatario.it", "Invio", $email_body, $email_headers);
but there was no file attached
Jul 17 '05 #1
1 3119
Agenzia Petracca wrote:
i wanna send html files (even *.doc) in the body of a mail with this code:
[Code snipped.]
WHERE IS THE MISTAKE?


Well, here are some mistakes:

1. Missing linebreak at the end of a header line.

2. Boundaries prefixed with a single hyphen.

3. No data in the "HTML" part.

4. Not providing a text/plain alternative (even worse mistake:
sending so-called HTML mail in the first place).

There are more.

You could read the article referenced from The Manual; or, rather
than reinventing the wheel, you might try a class prewritten for
this purpose, such as M. Lemos' class. (I haven't used it and
therefore can't vouch for it.)
http://www.phpclasses.org/mimemessage

--
Jock
Jul 17 '05 #2

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

Similar topics

11
by: ColinWard | last post by:
Hi. I have the following code in a module which sends email via Outlook. Option Compare Database Option Explicit ' Declare module level variables Dim mOutlookApp As Outlook.Application Dim...
0
by: Richard | last post by:
First some background... I have an application whereby I send a mail, attach some attachments stored in the windows/temp directory and then send them. This works fine on 2 servers both are not...
8
by: windandwaves | last post by:
Hi Folk I want to send out a basic newsletter from my MySql database of contacts. Does anyone know a nice and simple bit of PHP that allows me to do this? TIA - Nicolas
8
by: Robert Dufour | last post by:
Dim message As New MailMessage("mymail@mydomain.com", "mymail@mydomain.com", "Test", "Test") Dim emailClient As New SmtpClient("localhost") emailClient.Send(message) The IIS server is...
1
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...
4
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...
11
jamesd0142
by: jamesd0142 | last post by:
'server address Dim client As New SmtpClient("imap.uk.aol.com", 143) 'username and password client.Credentials = New Net.NetworkCredential("my username", "mypassword") ...
0
by: =?Utf-8?B?V2lsbGlhbSBHUw==?= | last post by:
Hello everybody. My app has a files list and I need to send by e-mail the selected files (could be 1 or more), I mean, the selected files must appear attached in a e-mail in the default e-mail...
1
by: charbel007 | last post by:
Iam stuck in the php mailer; and iam using the checkbox and it has been one month i can not solve it; when i select one checkbox from several ones , and i click send e-mail= it is sending to all...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.