I have an html page with a place
to add 1 file.
and a php3 email script that allows me
to attach this file (whatever type).
I can't get it to work can someone
please help me.
Below is my script.<?php
/*******************************************************/
/ S T A R T O F C L A S S /
/*******************************************************/
class mime_mail
{
var $parts;
var $to;
var $from;
var $headers;
var $subject;
var $body;
/*************************************/
/* CLASS CONSTRUCTOR */
/*************************************/
function mime_mail()
{
$this->parts = array();
$this->to = "";
$this->from = "";
$this->headers = "";
$this->subject = "";
$this->body = "";
}
/*************************************/
/* ADD ATTACHMENT TO MAIL OBJECT */
/*************************************/
function add_attachment($message, $name="", $ctype="application/octet-stream")
{
$this->parts[] = array (
"ctype" => $ctype,
"message" => $message,
"encode" => $encode,
"name" => $name
);
}
/*************************************/
/* BUILD MSG PARTS OF MULTIPART MAIL */
/*************************************/
function build_message($part)
{
$message = $part[ "message"];
$message = chunk_split(base64_encode($message));
$encoding = "base64";
return "Content-Type: ".$part[ "ctype"].
($part[ "name"]? "; name = \"".$part[ "name"]. "\"" : "").
"\nContent-Transfer-Encoding: $encoding\n\n$message\n";
}
/*************************************/
/* BUILD A MULTIPART MAIL */
/*************************************/
function build_multipart()
{
$boundary = "b".md5(uniqid(time()));
$multipart = "Content-Type: multipart/mixed; boundary = $boundary\n\nThis is a MIME encoded message.\n\n--$boundary";
for($i = sizeof($this->parts)-1; $i >= 0; $i--)
{
$multipart .= "\n".$this->build_message($this->parts[$i]). "--$boundary";
}
return $multipart.= "--\n";
}
/*************************************/
/* SEND THE MAIL */
/*************************************/
function send()
{
$mime = "";
if (!empty($this->from))
$mime .= "From: ".$this->from. "\n";
if (!empty($this->headers))
$mime .= $this->headers. "\n";
if (!empty($this->body))
$this->add_attachment($this->body, "", "text/plain");
$mime .= "MIME-Version: 1.0\n".$this->build_multipart();
mail($this->to, $this->subject, "", $mime);
}
}
/*******************************************************/
/ E N D O F C L A S S /
/*******************************************************/
/*******************************************************/
/ S T A R T O F P R O G R A M /
/*******************************************************/
/****************************************/
/* READ IN FILE TO ATTACH TO EMAIL */
/****************************************/
if ($File1 != "none")
{
copy ($File1, "$File1_name");
$fp = fopen ($File1, "r");
$file_size = filesize ($File1);
$Attach1 = fread ($fp, $file_size);
fclose ($fp);
}
else
{
print "No file selected";
return;
}
print "got to here 1<br>";
/****************************************/
/* SEND THE MAIL */
/****************************************/
$mail = new mime_mail();
print "got to here 2<br>";
$mail->from = "kathyc@bserv.com";
$mail->headers = "Errors-To: mail.bserv.com";
$mail->to = "kathyc@bserv.com";
$mail->subject = "Testing...";
$mail->body = "hi there";
print "got to here 3<br>";
$mail->add_attachment($Attach1, $File1, "image/jpg");
print "never got to here 4<br>";
$mail->send();
print "got to here - finished";
?>