Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sending email attaching - how do you declare the file path?

Status
Not open for further replies.

DrQuincy

Programmer
Jan 28, 2003
5
GB
Hi there,

I'm trying to create a form that sends an email with a .zip file attached. I'm using the following code I found on the Internet:
Code:
<?php

function sendmsg($to, $subject, $text, $from, $file, $type) {
	$content = fread(fopen($file,&quot;r&quot;),filesize($file));
	$content = chunk_split(base64_encode($content));
	$uid = strtoupper(md5(uniqid(time())));
	$name = basename($file);

	$header = &quot;From: $from\nReply-To: $from\n&quot;;
	$header .= &quot;MIME-Version: 1.0\n&quot;;
	$header .= &quot;Content-Type: multipart/mixed; boundary=$uid\n&quot;;

	$header .= &quot;--$uid\n&quot;;
	$header .= &quot;Content-Type: text/plain\n&quot;;
	$header .= &quot;Content-Transfer-Encoding: 8bit\n\n&quot;;
	$header .= &quot;$text\n&quot;;

	$header .= &quot;--$uid\n&quot;;
	$header .= &quot;Content-Type: $type; name=\&quot;$name\&quot;\n&quot;;

	$header .= &quot;Content-Transfer-Encoding: base64\n&quot;;
	$header .= &quot;Content-Disposition: attachment; filename=\&quot;$name\&quot;\n\n&quot;;
	$header .= &quot;$content\n&quot;;

	$header .= &quot;--$uid--&quot;;

	mail($to, $subject, &quot;&quot;, $header);

	return true;
}

sendmsg(&quot;submit@codeinthewhole.com&quot;, &quot;Hi Code in the Whole Webmaster&quot;, &quot;Hi Code in the Whole Webmaster!\n\nyou have a great script!&quot;, &quot;Tim Bennett&quot;, &quot;attach_test.zip&quot;, &quot;application/x-zip-compressed&quot;);

?>
The email gets sent and everything but the .zip arrives empty. What I want to know is how do you tell it where to look for the attachment. For example if I change the $file paramter to &quot;C:\\attach_test.zip&quot; it sends the email with an attachment named &quot;C:\\attach_test.zip&quot; instead of looking for it on my C drive.

Thanks. :)
 
As far as I know (I must admit I'm not a big expert as to mail...) you can't just call a &quot;local&quot; file from your web server (unless you are using a local web and mail server). Try your function sending a file that physically is located on the web server, and you see that the functioin (I hope) will work. If you really need to send a local file, I fear that you have to &quot;upload&quot; it before. To do this, you have to upload the file via HTTP POST. For further information on how to do it, refer to:


Good luck!
Gaetano
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top