Re: attaching files to a form to email script
| From: | Daniel Convissor | Date: | Tue, 10 Oct 2000 19:23:43 +0000 |
| Subject: | Re: attaching files to a form to email script | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-19446@lists.php.net to get a copy of this message | ||
Hi Jerry:
> I having a difficult time being able
> to implement file attachments into some
> form handling scripts I made. I've read
This is a summary of some code that does the job. Summarized for clarity.
Summary not tested...
$Boundary = ereg_replace(" ", "", microtime() );
$AttachHandle = fopen("$AttachFile","r")
$AddHead = "From: $FromName <$FromEmail>";
$AddHead .= "\nMIME-Version: 1.0";
$AddHead .= "\nContent-Type: multipart/mixed;
boundary=\"------------$Boundary\"";
$Output .= "\nThis is a multi-part message in MIME format.";
$Output .= "\n--------------$Boundary";
$Output .= "\nContent-Type: text/plain; charset=us-ascii";
$Output .= "\nContent-Transfer-Encoding: 7bit";
$Output = "\n\nI N S E R T Y O U R M E S S A G E H E R E";
$Output .= "\n\n--\n";
while ( $Temp = fgets($SignatureHandle, 100) ) {
$Output .= "$Temp";
}
$Output .= "\n\n";
$Output .= "--------------$Boundary";
$Output .= "\nContent-Type: application/x-zip-compressed;
name=\"$Form->AttachFile\"";
$Output .= "\nContent-Transfer-Encoding: base64";
$Output .= "\nContent-Disposition: attachment;
filename=\"$Form->AttachFile\"\n\n";
$Output .= chunk_split( base64_encode( fread( $AttachHandle,
filesize("$AttachFile") ) ) );
$Output .= "--------------$Boundary--";
mail("$Email", "$Subject", "$Output", "$AddHead");
--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
More than just answers. Solutions. (SM)
http://www.analysisandsolutions.com/
4015 7 Av #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409