473,804 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sent attachment received as empty attachment.txt?

Hi there, my problem is as follows:

When emailing a file using PHP 4.0.6, the attachment received is an
empty "attachment.txt " file instead of the actual file I attached.

Any suggestions why this might be? (php from a kindly newbie site enclosed)

Many thanks, Alan.

--------------begin extracted php---------------
<?php
// initialize variables for
// any errors
$errors = "";
$agreement = "no";

if ($HTTP_SERVER_V ARS['REQUEST_METHOD ']=="POST"){
// we'll begin by assigning the To address and message subject
$to="he***@test domain.com";
$subject="Test email";

// get the sender's name and email address
// we'll just plug them a variable to be used later
$from =
stripslashes($H TTP_POST_VARS['fromname'])."<".stripslas hes($HTTP_POST_ VARS['fromemail']).">";

// generate a random string to be used as the boundary marker
$mime_boundary= "==Multipart_Bo undary_x".md5(m t_rand())."x";

// store the file information to variables for easier access
$tmp_name = $HTTP_FILES_VAR S['filename']['tmp_name'];
$type = $HTTP_FILES_VAR S['filename']['type'];
$name = $HTTP_FILES_VAR S['filename']['name'];
$size = $HTTP_FILES_VAR S['filename']['size'];

// here we'll hard code a text messge
// again, in reality, you'll normally get this from the form submission
$message = "Message sent by $from\n";
// if the upload succeeded, the file will exist
if (file_exists($t mp_name)){

// check to make sure that it is an uploaded file and not a
system file
if(is_uploaded_ file($tmp_name) ){

// open the file for a binary read
$file = fopen($tmp_name ,'rb');

// read the file content into a variable
$data = fread($file,fil esize($tmp_name ));

// close the file
fclose($file);

// now we encode it and split it into acceptable length lines
$data = chunk_split(bas e64_encode($dat a));
}

// now we'll build the message headers
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mi me_boundary}\"" ;

// next, we'll build the message body
// note that we insert two dashes in front of the
// MIME boundary when we use it
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary }\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";

// now we'll insert a boundary to indicate we're starting the
attachment
// we have to specify the content type, file name, and disposition as
// an attachment, then add the file content and set another
boundary to
// indicate that the end of the file has been reached
$message .= "--{$mime_boundary }\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\ "\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fi leatt_name}\"\n " .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary }--\n";

// now we just send the message
if (@mail($to, $subject, $message, $headers))
echo "Your message has been sent.";
else
echo "Failed to send";
}
} else {
?>
<p>Send an e-mail with an attachment:</p>
<form action="<?php echo $HTTP_SERVER_VA RS['PHP_SELF']; ?>" method="post"
enctype="multip art/form-data" name="form1">
<p>From name: <input type="text" name="fromname" ></p>
<p>From e-mail: <input type="text" name="fromemail "></p>
<p>File: <input type="file" name="filename" ></p>
<p><input type="submit" name="Submit" value="Submit"> </p>
</form>
<?php } ?>
--------------end extracted php---------------
Jul 17 '05 #1
1 3850
Alan,
Did you ever get this figured out?

Thanks,
Bob

Jul 17 '05 #2

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

Similar topics

10
3708
by: Randell D. | last post by:
Folks, Perhaps someone can figure this out - this is 'the process of my script' I have a form whereby I can add multiple contacts to a single address. There is only one firstname/lastname/telephone box - when the user clicks the add button, I read the values from the form fields and record them into a hidden text input field. This part works because during debugging, I have converted the <input type=hidden> into a <input type=text>...
2
3788
by: bruce | last post by:
I can send an email from any client (outlook, lotus notes), and fill it with all sorts of fonts (bold, courier, etc). When the mail is received, the client reads it inline, not as an attachment. When I send an html email thru my Visual Basic program (using standard SMTP protocol), it is received as an attachment. How can I get it so that it is read inline? Thanks, Bruce Brodinsky
1
1622
by: bonokoot | last post by:
Hello, I wrote this program in C# that accesses a SQL Server database that runs a stored procedure and sents the results in an email every 30min. I wrote this as a windows application instead of a windows service, so the application is run every 30min through a scheduled task. When the email is received the received time is ok, but the sent time is incorrect. In some emails the sent date/time is the same displaying that the email was...
2
6880
by: Macca | last post by:
My app has an asynchronous socket server. It will have 20 clients connected to the server. Each client sends data every 500 millisecondsThe Connections once established will not be closed unless there is a problem with the connection. I need to know which client has sent the incoming data as each client has its own buffer on my "server" app. I am using the standard asynch socket code from MSDN to listen for connections and they...
1
5912
by: theWizard1 | last post by:
The following sends my email, but the attachment is empty. The attachment should contain the data that is in the string that was created from the xmlReader. I have a stored procedure written using For XML explicit, and it returns an xml reader. Then the following: xmlRdr.MoveToContent(); string myTemp = xmlRdr.ReadOuterXml();
1
2450
by: William Connery | last post by:
Hi, I have a small python program with e-mail capabilities that I have pieced together from code snippets found on the internet. The program uses the smtplib module to successfully send an e-mail with an attachment. I want to give users an indication of the percentage of the e-mail that has already been sent so as to avoid frustration when dealing with large attachments or a slow smtp server. But the smtplib module doesn't seem to...
0
1393
by: GLH42 | last post by:
Hi, I have a rather surreal problem in that emails sent from an Oracle Forms applications are having the attachment and the email body transposed. If an html attachment is sent, the email will arrive; but the email body will be an html attachment and the original html attachment will be a truncated mass of raw html code embedded within the email body. If a PDF is sent as the attachemnt, the original body is once again attached as html;...
2
4294
by: Erik Witkop | last post by:
So I have been trying to get this to work all day. I can't get a local file on my web server to attach to an email. Right now I have it printing out in the body of the email. Please help me with any thouhgts on how to get it in as an attachment. CODE: <?php ini_set(SMTP, "172.18.1.65");
1
1423
by: =?Utf-8?B?QnJhc3NpY2FOaWdyYQ==?= | last post by:
Greetings, This question does not seem to fit any of the forum headers so I picked the most general sounding forum I could find. My laptop is running Vista Ultimate. I use yahoo.com for business email and use their web based email client for my business account. Yesterday I received an email with a .pdf attachment. When I went to save the attachment the browser window refreshed but no dialog appeared asking me
0
10595
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10341
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10089
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7634
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5530
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4308
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

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.