Sending Attachment with PHP form and PEAR

edited April 2008 in Internet & Media
Can anyone steer me in the right direction here. I've created php forms that allow the user to send an attachment before, but now the server I'm on uses PEAR for email sending.

Here is my coding...

require_once("Mail.php");
require_once("Mail/mime.php");

$attach_name = $_FILES["attach"]["name"];
$attach_type = $_FILES["attach"]["type"];
$attach_size = ($_FILES["attach"]["size"] / 1024);
$attach_temp = $_FILES["attach"]["tmp_name"];

if (is_uploaded_file($attach)) {
$fp = fopen($attach, "rb");
$data = fread($fp, filesize($attach));
$data = chunk_split(base64_encode($data));
fclose($fp);
}

$uploaddir = "upload/";
if (move_uploaded_file($_FILES["attach"]["tmp_name"], $uploaddir .
$_FILES["attach"]["name"])) {
print "File is valid, and was successfully uploaded.";
} else {
print "There were some errors!";
}

$file = "(don't know what to put here!! needs to be the attachment!!)

$mime = new Mail_mime();

$mime->setTXTBody($text);
$mime->addAttachment($file,"application/octet-stream");

$body = $mime->get();
$headers = $mime->headers(array("From" => "from email", "Subject" => "subject"));

$params["host"] = 'smtp server';
$params["port"] = "25";
$params["auth"] = true;
$params["username"] = 'username';
$params["password"] = "password";

$mail =& Mail::factory("smtp", $params);
if(!$mail->send("email address",$headers,$body)) {
echo "Could not send email";
}
?>


I have it working to the point where I can upload the file to the server. I don't really WANT to upload the file to the server, I want to email it. I just added the uploading part to make sure I was getting the file info correct.

My main problem is, prior to running into PEAR, I was able to add header and message information regarding MIME content, etc. But as far as I can tell I can't do that with PEAR...

Don't know if I've explained this well....but any help would be appreciated! Thanks
Sign In or Register to comment.