I have this code. But it's not working. Please give me some code in PHP, so that I can attach a file using an HTML form and send it to some email address. The file type (I want .zip only) and size (I want 2 MB max) needs to be checked before emailing.

Here goes the code:

$req_id = time();
$new_file="public_html/uploads/" . $req_id . ".zip";

if (($_FILES["file"]["type"] == "application/zip") && ($_FILES["file"]["size"] < 10000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Fatal Error! Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
      move_uploaded_file($_FILES["file"]["tmp_name"], $new_file);
    }
  }
else
  {
  Print "<strong>There was an error while processing your request. Your query for quotation is not submitted successfully.</strong><br /><font color='red'>ERROR!<br>The attached file is not invalid. Either the file size is greater than 10 MB or the file type is not ZIP. Please check and try again.</font><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>";
  }

Recommended Answers

All 4 Replies

i think i have the code you need.

view post #12, it should be by me where it gives a sample code of how to use an email class i made. this script is attached to that post as well.

http://www.daniweb.com/forums/thread148350.html

if you have any questions on how to use it, let me know and i will try to answer them.

no. i want to upload it from an html form and then email it. ur code is not doing that. also, where to find that class.email.php file? i need and html form with file input box, which file will be emailed to an email id.

create a form with an file input type and then my script will automatically read the uploaded files and send them to an email address. if you want to use an id, you will have to query the database and get the email and then have it put that email into the $email->to($email); function. i have used this to do what you are asking exactly so i know it works.

the class.email.php is attached to my post in that thread.

Thank you kkeith29
Your script is working. I'm grateful to you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.