Ok, I am close (i think) to getting this class to work. I receive an email that contains no attachment but includes the encoded file in the message. I am confused how to pass '$file' to this function.
Code: Select all
function addAttachment ( $filename, $file, $mimetype ) {
$this->files[$filename] = array( "MIME" => $mimetype, "FILE" => $file );
}
here is my code, please help:
Code: Select all
<?php
include("email.php");
#variables
$to ="me@email.com";
$from ="you@email.com";
$subject="File Attachement";
$message = "See attachment...";
if ($_FILES) {
#ALLOWED FILE TYPES
$image_types = Array ("image/bmp",
"image/jpeg",
"image/pjpeg",
"image/gif",
"image/tiff",
"image/png",
"image/x-png",
"application/octet-stream");
#IF THE FILE UPLOADS SET USERFILE AND BUILD VARIABLES
if (is_uploaded_file ($_FILES['userfile']['tmp_name'])) {
$userfile = addslashes (fread (fopen($_FILES["userfile"]["tmp_name"], "r"), filesize($_FILES["userfile"]["tmp_name"])));
$file_name = $_FILES["userfile"]["name"];
$file_size = $_FILES["userfile"]["size"];
$file_type = $_FILES["userfile"]["type"];
}
}
if ($_POST){
$email = new email($to, $from, $subject, $message);
$email->addAttachment ( $file_name, $userfile, $file_type); <---how should I pass the file?
$email->sendEmail();
}
?>
<html>
<head>
<title>Send Email Attachment</title>
</head>
<body>
<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="24000000">
<input type="file" name="userfile" size="60"><br><br>
<input type="submit" name="submit" value="Send Email">
</form>
</body>
</html>
Thanks!